fread() fails with large files
| From: | Sora B. Harbater | Date: | Sun, 03 Nov 2002 13:44:11 +0000 |
| Subject: | fread() fails with large files | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-122555@lists.php.net to get a copy of this message | ||
Hi. I am using Linux/Apache with PHP 4.1.2. I have been experiencing this problem since upgrading from an earlier version of PHP 4.
My script forces a download of a PDF file after looking up some info in a database. The code looks like this:
$file="/path/to/file";
$fp = fopen($file, "r");
$size=filesize($file);
$contents = fread($fp, $size);
fclose($fp);
Header("Content-Type: $type");
Header("Content-Disposition: attachment; filename=$downloadname");
header("Content-Length: $size");
header("Content-Transfer-Encoding: binary");
echo $contents;
filesize() is reporting the size properly. The code works perfectly for smaller files, but the fread() fails for files larger than 19 MB or so and I got a page cannot be displayed error. I know that it is fread() which is causing the problem because I commented out all the code that follows it and still get the error. All the files being downloaded are PDF files.
Can anyone shed some light on this?