0

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...

4

1 回答 1

1

我猜你echo "here"; die();在问这个问题之前删除了。

任何人,您的本地计算机和网络主机上的文件结构是否相同?

该文件实际上在../中吗?也许尝试使用文件的完整路径?/home/youruser/public_html/ 或任何主机的目录结构。

于 2012-04-27T05:43:27.567 回答