Created
July 19, 2011 14:41
-
-
Save jrtashjian/1092582 to your computer and use it in GitHub Desktop.
Chunk File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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