Skip to content

Commit

Permalink
Try to fix download buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
gubi committed Feb 25, 2014
1 parent 0099752 commit 2ec735c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion common/include/funcs/download.php
@@ -1,6 +1,29 @@
<?php
header("Content-type:text/plain; charset=utf-8");
require_once("common/include/classes/rsa.class.php");
function readfile_chunked($filename, $retbytes = true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}

$rsa = new rsa();
$url = parse_url($_SERVER["REQUEST_URI"]);
Expand Down Expand Up @@ -95,7 +118,7 @@
header("Content-Length: " . $file_size); // provide file size
header("Connection: close");

@readfile($file);
@readfile_chunked($file);
}
exit();
}
Expand Down

0 comments on commit 2ec735c

Please sign in to comment.