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" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to