diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 55bed7ea79..1ad6dfc092 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -47,8 +47,17 @@ function send_avatar_to_browser($file, $browser) if ($storage->exists($file_path) && !headers_sent()) { + $file_info = $storage->file_info($file_path); + header('Cache-Control: public'); + try { + header('Content-Type: ' . $file_info->mimetype); + } catch (\phpbb\storage\exception\not_implemented $e) { + // Just dont send this header + } + + if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7)) { header('Content-Disposition: attachment; ' . header_filename($file)); @@ -68,6 +77,12 @@ function send_avatar_to_browser($file, $browser) header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); } + try { + header('Content-Type: ' . $file_info->size); + } catch (\phpbb\storage\exception\not_implemented $e) { + // Just dont send this header + } + if (@readfile($file_path) == false) { $fp = @fopen($file_path, 'rb'); @@ -82,7 +97,18 @@ function send_avatar_to_browser($file, $browser) } } - echo $storage->get_contents($file_path); + try { + $fp = $storage->read_stream($file_path); + + while (!feof($fp)) + { + echo fread($fp, 8192); + } + + fclose($fp); + } catch (\Exception $e) { + + } flush(); } diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index a614860030..9e7dc7db79 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -236,17 +236,17 @@ class local implements adapter_interface, stream_interface } } - public function get_file_info($path) + public function file_properties($path) { return []; } - public function get_size($path) + public function file_size($path) { return filesize($this->root_path . $path); } - public function get_mimetype($path) + public function file_mimetype($path) { return mime_content_type($this->root_path . $path); } diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index a3bcfbabba..f78bc88d10 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -35,7 +35,7 @@ class file_info { $this->properties = []; - foreach($this->adapter->get_file_info($this->path) as $name => $value) { + foreach($this->adapter->file_properties($this->path) as $name => $value) { $this->properties[$name] = $value; } } @@ -47,12 +47,12 @@ class file_info if (!isset($this->properties[$name])) { - if (!method_exists($this->adapter, 'get_' . $name)) + if (!method_exists($this->adapter, 'file_' . $name)) { throw new not_implemented(); } - $this->properties[$name] = call_user_func($this->adapter, 'get_' . $name); + $this->properties[$name] = call_user_func($this->adapter, 'file_' . $name); } return $this->properties[$name]; diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 3ecf0f97af..59181d2623 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -193,8 +193,8 @@ class storage } } - public function get_fileinfo($path) + public function file_info($path) { - return new file_info($adapter, $path); + return new file_info($this->adapter, $path); } }