note 52598 added to function.readfile
| From: | flobee at gmail dot com | Date: | Fri, 06 May 2005 18:17:32 +0000 |
| Subject: | note 52598 added to function.readfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89013@lists.php.net to get a copy of this message | ||
regarding php5:
i found out that there is already a disscussion @php-dev about readfile() and fpassthru() where
only exactly 2 MB will be delivered.
so you may use this on php5 to get lager files
<?php
function readfile_chunked($filename,$retbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.readfile.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52598
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52598&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52598&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52598&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52598&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52598&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52598&report=yes
Search -- http://master.php.net/manage/user-notes.php