mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
[ticket/14285] Move downloads to controller
PHPBB3-14285
This commit is contained in:
@@ -19,83 +19,6 @@ if (!defined('IN_PHPBB'))
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simplified function to deliver avatars
|
||||
* The argument needs to be checked before calling this function.
|
||||
*/
|
||||
function send_avatar_to_browser($file, $browser)
|
||||
{
|
||||
global $config, $phpbb_container;
|
||||
|
||||
$storage = $phpbb_container->get('storage.avatar');
|
||||
|
||||
$prefix = $config['avatar_salt'] . '_';
|
||||
$file_path = $prefix . $file;
|
||||
|
||||
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\exception $e)
|
||||
{
|
||||
// Just don't send this header
|
||||
}
|
||||
|
||||
if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7))
|
||||
{
|
||||
header('Content-Disposition: attachment; ' . header_filename($file));
|
||||
|
||||
if (strpos(strtolower($browser), 'msie 6.0') !== false)
|
||||
{
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
||||
}
|
||||
else
|
||||
{
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
header('Content-Disposition: inline; ' . header_filename($file));
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
header('Content-Length: ' . $file_info->size);
|
||||
}
|
||||
catch (\phpbb\storage\exception\exception $e)
|
||||
{
|
||||
// Just don't send this header
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$fp = $storage->read_stream($file_path);
|
||||
$output = fopen('php://output', 'w+b');
|
||||
stream_copy_to_stream($fp, $output);
|
||||
fclose($fp);
|
||||
fclose($output);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// Send nothing
|
||||
}
|
||||
|
||||
flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps an url into a simple html page. Used to display attachments in IE.
|
||||
* this is a workaround for now; might be moved to template system later
|
||||
|
Reference in New Issue
Block a user