Welcome Guest, Not a member yet? Register   Sign In
Using Download Helper With Extremely Large Files
#10

[eluser]dawnerd[/eluser]
I did some reason on the readfile function and I found that through some sly programming, you can mimic the readfile function, but have it read the file in chucks, thus avoiding the max memory errors.

Here's the code that was posted on php.net

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

}
?>

I'm sure I'm not the only one that could use this. Now, to get it to work in code igniter...


Messages In This Thread
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 12:07 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 12:26 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 12:31 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 02:14 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 02:18 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 02:25 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 02:36 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 02:43 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 02:50 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 03:03 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 03:11 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 03:15 AM
Using Download Helper With Extremely Large Files - by El Forum - 01-19-2008, 10:14 AM
Using Download Helper With Extremely Large Files - by El Forum - 12-09-2008, 05:08 AM
Using Download Helper With Extremely Large Files - by El Forum - 07-28-2011, 08:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB