I need to authenticate user to view/download some of the files in my site. My files are located in a folder say A inside public_html/mySiteName/FoldesName(A)/subFolder/sample.(*.*)
. I used .htaccess
to check that the user is authenticated or not.
MY .htaccess
code :
RewriteEngine on # Enable rewrite
RewriteCond %{REQUEST_FILENAME} \.*pdf$|.*psd$|.*indd$ [NC]
RewriteRule (.*) http://MySiteIp/admin_panel/auth.php?file=$1 [NC,L]
My download script looks like :
if($authed){
if(file_exists("../".$_GET['file'])) {
//Create the pointer to our file and open it as read-only binary data
$fp = fopen($file,'rb');
// Send headers telling browser to download our passed data
header("Content-Type: application/force-download");
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . filesize($file));
header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=\"$file\"");
while (!feof($fp)) {
echo(@fgets($fp, 8192));
}
//Here comes the data
fclose($fp);
//and quit
exit;
} else {
echo "No file exists !!!";
}
}
When I test it on my local machine with Xampp Server installed on it. It works. But on my host I get the error message "NO file exists".
Please help me to find where I am wrong...