diff options
author | Andreas Fischer <bantu@phpbb.com> | 2010-06-23 16:26:53 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2010-10-23 18:04:16 +0200 |
commit | 18e55708518fc53f5b134235895328de03680521 (patch) | |
tree | ab0948c00f0426373389da5277b9c0dd4f2bd844 /phpBB/includes/functions_download.php | |
parent | 56b0268d1de0575018fd542b9d1b9b71b88c1057 (diff) | |
download | forums-18e55708518fc53f5b134235895328de03680521.tar forums-18e55708518fc53f5b134235895328de03680521.tar.gz forums-18e55708518fc53f5b134235895328de03680521.tar.bz2 forums-18e55708518fc53f5b134235895328de03680521.tar.xz forums-18e55708518fc53f5b134235895328de03680521.zip |
[ticket/9627] Make use of 'static' since the function is called more than once
PHPBB3-9627
Diffstat (limited to 'phpBB/includes/functions_download.php')
-rw-r--r-- | phpBB/includes/functions_download.php | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 606d6eec32..7013a80418 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -447,30 +447,49 @@ function file_gc() */ function http_byte_range($filesize) { + // The range request array; + // contains all requested ranges. + static $request_array; + if (!$filesize) { return false; } - foreach (array($_SERVER, $_ENV) as $global) + if (!isset($request_array)) { - if (isset($global['HTTP_RANGE'])) + $request_array = false; + + $globals = array( + array('_SERVER', 'HTTP_RANGE'), + array('_ENV', 'HTTP_RANGE'), + ); + + foreach ($globals as $array) { - $http_range = $global['HTTP_RANGE']; - break; + $global = $array[0]; + $key = $array[1]; + + // Make sure range request starts with "bytes=" + if (isset($GLOBALS[$global][$key]) && strpos($GLOBALS[$global][$key], 'bytes=') === 0) + { + // Strip leading 'bytes=' + // Multiple ranges can be separated by a comma + $request_array = explode(',', substr($GLOBALS[$global][$key], 6)); + + break; + } } } // Return if no range requested - // Make sure range request starts with "bytes=" - if (empty($http_range) || strpos($http_range, 'bytes=') !== 0) + if (empty($request_array)) { return false; } - // Strip leading 'bytes=' - // Multiple ranges can be separated by a comma - foreach (explode(',', substr($http_range, 6)) as $range_string) + // Go through all ranges + foreach ($request_array as $range_string) { $range = explode('-', trim($range_string)); |