Skip to content

Instantly share code, notes, and snippets.

@jrtashjian
Created July 19, 2011 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrtashjian/1092582 to your computer and use it in GitHub Desktop.
Save jrtashjian/1092582 to your computer and use it in GitHub Desktop.
Chunk File
<?php
/**
* This function will read the file passed to it at 1MB/s and output it to the
* browser.
*/
function readfile_chunked( $filename )
{
$rate = 1024;
$file = fopen($filename, 'rb');
while( !feof($file) )
{
print fread($file, round($rate * 1024));
flush();
ob_flush();
sleep(1);
}
fclose($file);
exit;
}
$file = 'http://domain.com/path/to/file.extension';
readfile_chunked($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment