From 18e55708518fc53f5b134235895328de03680521 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Jun 2010 16:26:53 +0200 Subject: [PATCH] [ticket/9627] Make use of 'static' since the function is called more than once PHPBB3-9627 --- phpBB/includes/functions_download.php | 37 ++++++++++++++++++++------- 1 file 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));