None have worked for me so far. The only thing that works without fail is presenting a link to the file in a folder on the web path, but that defeats the purpose of keeping files off the web path to prevent script execution. The latest thing I have tried is fopen(), but I get an error: "(IE7) cannot download download.php (the download page) from (website)". It seems the page is trying to download itself instead of the given file. I won't bore you with the entire code, but suffice to say I do a lot of checking before I get to this:
if(file_exists($thefile) && is_readable($thefile)) // Make sure file exists in source
{
// File exists & is readable, but fails here:
$fp = fopen($thefile, "rb");
header("Content-type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($thefile));
header("Content-disposition: attachment; filename='".$filename."')");
fpassthru($fp);
exit;
I should add that I am using:
SUSE Linux
Apache 1.3
PHP 4.3
* OpenSSL .9
(I suspect SSL may be the problem)
The file itself is in the /uploads/ folder in the server root with 777 permissions and chown to "nobody:nobody". I've stored $thefile with a random hash string for a name, which is why I rename it to the original $filename in line 8.
Any suggestions would be helpful. I'm open to using other methods that won't compromise on security. If its a version problem, I'm a few weeks away from an new Linux server, so should I just wait? The current server is live and serving another vital app, so I don't want to mess with upgrading it.