diff options
author | diosmosis <benakamoorthi@fastmail.fm> | 2014-06-19 06:01:45 +0400 |
---|---|---|
committer | diosmosis <benakamoorthi@fastmail.fm> | 2014-06-19 06:01:52 +0400 |
commit | f169ee42e8bc15ffa63b5589d16280aa10e88ee1 (patch) | |
tree | 758dae3cfd2d94f827756d5db2bbb74ed6016e46 /libs | |
parent | 6c1970444bb93e8bb1370f7248682fd7b515b308 (diff) |
Add ability to serve only part of a static file. Includes tests for new functionality.
Diffstat (limited to 'libs')
-rw-r--r-- | libs/upgradephp/upgrade.php | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/libs/upgradephp/upgrade.php b/libs/upgradephp/upgrade.php index 5ab68078a8..7d23172470 100644 --- a/libs/upgradephp/upgrade.php +++ b/libs/upgradephp/upgrade.php @@ -612,20 +612,27 @@ function safe_unserialize( $str ) * @param resource $context * @return int the number of bytes read from the file, or false if an error occurs */ -function _readfile($filename, $useIncludePath = false, $context = null) +function _readfile($filename, $byteStart, $byteEnd, $useIncludePath = false, $context = null) { $count = @filesize($filename); // built-in function has a 2 MB limit when using mmap - if (function_exists('readfile') && $count <= (2 * 1024 * 1024)) { + if (function_exists('readfile') + && $count <= (2 * 1024 * 1024) + && $byteStart == 0 + && $byteEnd == $count + ) { return @readfile($filename, $useIncludePath, $context); } // when in doubt (or when readfile() function is disabled) $handle = @fopen($filename, SettingsServer::isWindows() ? "rb" : "r"); if ($handle) { - while(!feof($handle)) { - echo fread($handle, 8192); + fseek($handle, $byteStart); + + for ($pos = $byteStart; $pos < $byteEnd && !feof($handle); $pos = ftell($handle)) { + echo fread($handle, min(8192, $byteEnd - $pos)); + ob_flush(); flush(); } |