Merged in readfile_chunked() patch -- much lower memory footprint, same CPU usage, works around PHP5 bug in readfile()

This commit is contained in:
martinlanghoff
2005-06-07 23:43:04 +00:00
parent 6eabcba137
commit 9fd70b1ac3
+24 -2
View File
@@ -167,7 +167,7 @@ function send_file($path, $filename, $lifetime=86400 , $filter=false, $pathisstr
if ($pathisstring) {
echo $path;
}else {
readfile($path);
readfile_chunked($path);
}
} else { // Try to put the file through filters
global $course; // HACK!
@@ -199,7 +199,7 @@ function send_file($path, $filename, $lifetime=86400 , $filter=false, $pathisstr
if ($pathisstring) {
echo $path;
}else {
readfile($path);
readfile_chunked($path);
}
}
}
@@ -344,5 +344,27 @@ function fulldelete($location) {
return true;
}
function readfile_chunked($filename,$retbytes=true) {
$chunksize = 1*(1024*1024); // 1MB chunks
$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;
}
?>