I thought I had an issue where fread() would fail on files
> 30M in size. I tried a file_get_contents() method with
the same results. The issue was not reading the file, but
echoing its data back to the browser.
Basically, you need to split up the filedata into manageable
chunks before firing it off to the browser:
<?php
$total = filesize($filepath);
$blocksize = (2 << 20); //2M chunks
$sent = 0;
$handle = fopen($filepath, "r");
// Push headers that tell what kind of file is coming down
the pike
header('Content-type: '.$content_type);
header('Content-Disposition: attachment;
filename='.$filename);
header('Content-length: '.$filesize * 1024);
// Now we need to loop through the file and echo out chunks
of file data
// Dumping the whole file fails at > 30M!
while($sent < $total){
echo fread($handle, $blocksize);
$sent += $blocksize;
}
exit(0);
?>
Hope this helps someone!
----
Server IP: 208.69.120.35
Probable Submitter: 24.123.63.138
----
Manual Page -- http:
//www.php.net/manual/en/function.fread.php
Edit -- https://master
.php.net/note/edit/78406
Del: integrated -- h
ttps://master.php.net/note/delete/78406/integrated
Del: useless -- http
s://master.php.net/note/delete/78406/useless
Del: bad code -- htt
ps://master.php.net/note/delete/78406/bad+code
Del: spam -- https:/
/master.php.net/note/delete/78406/spam
Del: non-english --
https://master.php.net/note/delete/78406/non-english
Del: in docs -- http
s://master.php.net/note/delete/78406/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78406
Reject -- https://mast
er.php.net/note/reject/78406
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|