readfile()
| From: | Aaron Todd | Date: | Mon, 23 Aug 2004 18:02:07 +0000 |
| Subject: | readfile() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-194502@lists.php.net to get a copy of this message | ||
I'm trying to use readfile() to allow a user to download a file that is
outside of my webroot.
webroot = /var/www/html
downloads dir = /var/www/downloads
Here is the code that I have been using:
$file = "/var/www/downloads/test.txt";
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($file));
readfile($file);
This code will work if I change the path to the webroot path, but not the
downloads dir path. I get an error saying "Unable to access" and then
"failed to open stream: No such file or directory".
I have given whe I believe is the correct rights for the downloads dir and
also the file...rwxr-xr-x for both.
Anyone have any idea why this isnt working?
Thanks,
Aaron