Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files download buffering #19

Open
gubi opened this issue Feb 24, 2014 · 1 comment
Open

Files download buffering #19

gubi opened this issue Feb 24, 2014 · 1 comment

Comments

@gubi
Copy link
Owner

gubi commented Feb 24, 2014

Improve (and test) files download with this function recommended by Francesco Rapanà

<?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; 
       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; 

} 
?>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@gubi gubi added this to the First release milestone Feb 24, 2014
@gubi gubi added bug labels Feb 24, 2014
@gubi gubi self-assigned this Feb 24, 2014
@gubi
Copy link
Owner Author

gubi commented Feb 25, 2014

I tried to fix as suggested (2ec735c) but seems there's no changes.

@gubi gubi added the discussion label Mar 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant