Re: fread() fails with large files
| From: | rija | Date: | Sun, 03 Nov 2002 23:12:30 +0000 |
| Subject: | Re: fread() fails with large files | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-122583@lists.php.net to get a copy of this message | ||
Use readfile instead fread() if you've got some problem with, it looks
better!
Header("Content-Type: $type");
Header("Content-Disposition: attachment; filename=$downloadname");
header("Content-Length: $size");
header("Content-Transfer-Encoding: binary");
readfile($file);
----- Original Message -----
From: "Sora B. Harbater" <harbater@teamgenesis.com>
To: <php-general@lists.php.net>
Sent: Monday, November 04, 2002 12:44 AM
Subject: [PHP] fread() fails with large files
> 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?
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>