I want the log in user can access the PDF file and anonymous user can not access the file from browser like www.domain.com/pdf/name.pdf
My pdf file is getting corrupted.It is gets failed when clicked for download.
I have created pdf folder in that kept my all pdf. I have html code
<ul>
<li>
<a href="/check.php" target="_blank">Test</a>
</li>
</ul>
check.php file
if($_SESSION[login]==true){
$file_url = 'http://domainname.com/pdf/example.pdf';
$filename='example.pdf';
header("Content-Disposition: attachment; filename=" . urlencode($filename));
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file_url));
$fp = fopen($file_url, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
}
ht.access
RewriteEngine on
RewriteRule .* check.php