Hi,
Indeed a fclose($fp) is needed (wrote it as an example :)).
1MB is more than enough as a buffer. If you have a 53MB file,
what will happen then ?
I have no idea if it's a bug or a feature. Either way I did lose
some hair over this when I switched from PHP4 to PHP5.
Catalin
Jordan Miller wrote:
Catalin,
Wow, that worked great, thanks.
I'm curious why you set a static buffer of 1024768... why not just do
filesize($file), as shown at http://www.php.net/fread ? Is it better
for memory usage to have a potentially smaller buffer? Also, you may
want an fclose($fp) after the file has been downloaded.
So is this a bug in PHP 5 or are they just purposely limiting the
abilities of the "readfile" command?
Jordan
On Aug 17, 2005, at 3:36 AM, Catalin Trifu wrote:
Hi,
I've had a similar problem. The download always stopped at
exactly 2.000.000 bytes.
You have to work around that with:
$fp = fopen($file, 'r');
if($fp) {
while(!feof($fp)) {
echo fread($fp, 1024768);//see the huge buffer to read into
}
} else {
//whatever error handler
}
Catalin
Jordan Miller wrote:
Hello all,
I am new to this list and I have searched the archives to no avail.
I am having a peculiar problem when upgrading to PHP 5: My
downloads are now limited to the first 1.9 MB of the file in
question, with the download either terminating at 1.9 MB or
seemingly continuously stuck in a downloading process at 1.9 MB.
The code in the PHP script has not changed and all parameters that
I could find that are relevant to this problem are given below:
the minimal code needed for download:
// $file_to_read is the complete path of the file to download
header("Content-Type: application/pdf");
header( "Content-Disposition: inline; filename=\"$filename \"");
$len = filesize($file_to_read);
header("Content-Length: $len");
@readfile($file_to_read);
php.ini file for both php version 4 and 5 contain the following
settings that may be relevant:
allow_url_fopen = On
max_execution_time = 300 ; Maximum execution time of each
script, in seconds
max_input_time = 300 ; Maximum amount of time each script may
spend parsing request data
memory_limit = 8M ; Maximum amount of memory a script may
consume (8MB)
post_max_size = 200M
upload_max_filesize = 200M
Some additional details:
All files less than 1.9 MB download fine
It is not a corrupted file, because all files larger than 1.9 MB
fail after 1.9 MB
The connection is not timing out (download of 1.9 MB takes only ~15
sec)
Mac OS X 10.3.9 with Marc Liyanage's PHP 5.0.4
Fails for both Safari and Firefox
Fails regardless of "inline" or "attachment"
Fails regardless of "pdf" or "ppt" content-type
This PHP code ALWAYS works for Marc Liyanage's PHP 4.3.4 with the
same settings, above
What am I doing wrong??? Any other parameter in php.ini I should
have set? Any suggestions are much appreciated.
thanks,
Jordan
--
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