Forcing Download of file using php script on CentOs 5.6
<p>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 <code>public_html/mySiteName/FoldesName(A)/subFolder/sample.(*.*)</code>. I used <code>.htaccess</code> to check that the user is authenticated or not.</p>

<hr>

<p>MY <code>.htaccess</code> code :</p>

<pre><code>RewriteEngine on   # Enable rewrite
RewriteCond %{REQUEST_FILENAME} \.*pdf$|.*psd$|.*indd$ [NC]  
RewriteRule (.*) http://MySiteIp/admin_panel/auth.php?file=$1 [NC,L]
</code></pre>

<p>My download script looks like :</p>

<pre><code>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 !!!";
    }
}
</code></pre>

<p>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".</p>

<p>Please help me to find where I am wrong...</p>
