mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-07 17:27:16 +02:00
[ticket/15286] Use storage in attachments
PHPBB3-15286
This commit is contained in:
@@ -147,7 +147,6 @@ class acp_attachments
|
||||
|
||||
'allow_attachments' => array('lang' => 'ALLOW_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
|
||||
'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
|
||||
'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true),
|
||||
'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'custom', 'method' => 'display_order', 'explain' => true),
|
||||
'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
|
||||
'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
|
||||
@@ -223,9 +222,6 @@ class acp_attachments
|
||||
{
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_ATTACH');
|
||||
|
||||
// Check Settings
|
||||
$this->test_upload($error, $this->new_config['upload_path'], false);
|
||||
|
||||
if (!count($error))
|
||||
{
|
||||
trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
|
||||
@@ -1536,50 +1532,6 @@ class acp_attachments
|
||||
return $imagick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Settings
|
||||
*/
|
||||
function test_upload(&$error, $upload_dir, $create_directory = false)
|
||||
{
|
||||
global $user, $phpbb_root_path;
|
||||
|
||||
// Does the target directory exist, is it a directory and writable.
|
||||
if ($create_directory)
|
||||
{
|
||||
if (!file_exists($phpbb_root_path . $upload_dir))
|
||||
{
|
||||
@mkdir($phpbb_root_path . $upload_dir, 0777);
|
||||
|
||||
try
|
||||
{
|
||||
$this->filesystem->phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
|
||||
}
|
||||
catch (\phpbb\filesystem\exception\filesystem_exception $e)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!file_exists($phpbb_root_path . $upload_dir))
|
||||
{
|
||||
$error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_dir($phpbb_root_path . $upload_dir))
|
||||
{
|
||||
$error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->filesystem->is_writable($phpbb_root_path . $upload_dir))
|
||||
{
|
||||
$error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform operations on sites for external linking
|
||||
*/
|
||||
|
@@ -121,13 +121,15 @@ function wrap_img_in_html($src, $title)
|
||||
/**
|
||||
* Send file to browser
|
||||
*/
|
||||
function send_file_to_browser($attachment, $upload_dir, $category)
|
||||
function send_file_to_browser($attachment, $category)
|
||||
{
|
||||
global $user, $db, $phpbb_dispatcher, $phpbb_root_path, $request;
|
||||
global $user, $db, $phpbb_dispatcher, $request, $phpbb_container;
|
||||
|
||||
$filename = $phpbb_root_path . $upload_dir . '/' . $attachment['physical_filename'];
|
||||
$storage = $phpbb_container->get('storage.attachment');
|
||||
|
||||
if (!@file_exists($filename))
|
||||
$filename = $attachment['physical_filename'];
|
||||
|
||||
if (!$storage->exists($filename))
|
||||
{
|
||||
send_status_line(404, 'Not Found');
|
||||
trigger_error('ERROR_NO_ATTACHMENT');
|
||||
@@ -146,14 +148,22 @@ function send_file_to_browser($attachment, $upload_dir, $category)
|
||||
}
|
||||
|
||||
// Now send the File Contents to the Browser
|
||||
$size = @filesize($filename);
|
||||
try
|
||||
{
|
||||
$file_info = $storage->file_info($filename);
|
||||
$size = $file_info->size;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$size = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Event to alter attachment before it is sent to browser.
|
||||
*
|
||||
* @event core.send_file_to_browser_before
|
||||
* @var array attachment Attachment data
|
||||
* @var string upload_dir Relative path of upload directory
|
||||
* @var int category Attachment category
|
||||
* @var string filename Path to file, including filename
|
||||
* @var int size File size
|
||||
@@ -161,7 +171,6 @@ function send_file_to_browser($attachment, $upload_dir, $category)
|
||||
*/
|
||||
$vars = array(
|
||||
'attachment',
|
||||
'upload_dir',
|
||||
'category',
|
||||
'filename',
|
||||
'size',
|
||||
@@ -171,15 +180,8 @@ function send_file_to_browser($attachment, $upload_dir, $category)
|
||||
// To correctly display further errors we need to make sure we are using the correct headers for both (unsetting content-length may not work)
|
||||
|
||||
// Check if headers already sent or not able to get the file contents.
|
||||
if (headers_sent() || !@file_exists($filename) || !@is_readable($filename))
|
||||
if (headers_sent())
|
||||
{
|
||||
// PHP track_errors setting On?
|
||||
if (!empty($php_errormsg))
|
||||
{
|
||||
send_status_line(500, 'Internal Server Error');
|
||||
trigger_error($user->lang['UNABLE_TO_DELIVER_FILE'] . '<br />' . sprintf($user->lang['TRACKED_PHP_ERROR'], $php_errormsg));
|
||||
}
|
||||
|
||||
send_status_line(500, 'Internal Server Error');
|
||||
trigger_error('UNABLE_TO_DELIVER_FILE');
|
||||
}
|
||||
@@ -235,24 +237,6 @@ function send_file_to_browser($attachment, $upload_dir, $category)
|
||||
|
||||
if (!set_modified_headers($attachment['filetime'], $user->browser))
|
||||
{
|
||||
// We make sure those have to be enabled manually by defining a constant
|
||||
// because of the potential disclosure of full attachment path
|
||||
// in case support for features is absent in the webserver software.
|
||||
if (defined('PHPBB_ENABLE_X_ACCEL_REDIRECT') && PHPBB_ENABLE_X_ACCEL_REDIRECT)
|
||||
{
|
||||
// X-Accel-Redirect - http://wiki.nginx.org/XSendfile
|
||||
header('X-Accel-Redirect: ' . $user->page['root_script_path'] . $upload_dir . '/' . $attachment['physical_filename']);
|
||||
exit;
|
||||
}
|
||||
else if (defined('PHPBB_ENABLE_X_SENDFILE') && PHPBB_ENABLE_X_SENDFILE && !phpbb_http_byte_range($size))
|
||||
{
|
||||
// X-Sendfile - http://blog.lighttpd.net/articles/2006/07/02/x-sendfile
|
||||
// Lighttpd's X-Sendfile does not support range requests as of 1.4.26
|
||||
// and always requires an absolute path.
|
||||
header('X-Sendfile: ' . dirname(__FILE__) . "/../$upload_dir/{$attachment['physical_filename']}");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($size)
|
||||
{
|
||||
header("Content-Length: $size");
|
||||
@@ -261,7 +245,7 @@ function send_file_to_browser($attachment, $upload_dir, $category)
|
||||
// Try to deliver in chunks
|
||||
@set_time_limit(0);
|
||||
|
||||
$fp = @fopen($filename, 'rb');
|
||||
$fp = $storage->read_stream($filename);
|
||||
|
||||
if ($fp !== false)
|
||||
{
|
||||
@@ -291,10 +275,6 @@ function send_file_to_browser($attachment, $upload_dir, $category)
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
@readfile($filename);
|
||||
}
|
||||
|
||||
flush();
|
||||
}
|
||||
|
Reference in New Issue
Block a user