1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[ticket/15286] Use storage in attachments

PHPBB3-15286
This commit is contained in:
Rubén Calvo
2017-08-09 12:21:19 +02:00
parent 1c9798320e
commit e749e06042
12 changed files with 233 additions and 136 deletions

View File

@@ -20,6 +20,7 @@ use \phpbb\event\dispatcher;
use \phpbb\language\language;
use \phpbb\mimetype\guesser;
use \phpbb\plupload\plupload;
use \phpbb\storage\storage;
use \phpbb\user;
/**
@@ -51,6 +52,9 @@ class upload
/** @var plupload Plupload */
protected $plupload;
/** @var storage */
protected $storage;
/** @var user */
protected $user;
@@ -79,7 +83,7 @@ class upload
* @param user $user
* @param $phpbb_root_path
*/
public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, user $user, $phpbb_root_path)
public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, user $user, $phpbb_root_path)
{
$this->auth = $auth;
$this->cache = $cache;
@@ -89,6 +93,7 @@ class upload
$this->mimetype_guesser = $mimetype_guesser;
$this->phpbb_dispatcher = $phpbb_dispatcher;
$this->plupload = $plupload;
$this->storage = $storage;
$this->user = $user;
$this->phpbb_root_path = $phpbb_root_path;
}
@@ -118,7 +123,7 @@ class upload
return $this->file_data;
}
$this->file = ($local) ? $this->files_upload->handle_upload('files.types.local', $local_storage, $local_filedata) : $this->files_upload->handle_upload('files.types.form', $form_name);
$this->file = ($local) ? $this->files_upload->handle_upload('files.types.local_storage', $local_storage, $local_filedata) : $this->files_upload->handle_upload('files.types.form_storage', $form_name);
if ($this->file->init_error())
{
@@ -152,25 +157,12 @@ class upload
$this->file->clean_filename('unique', $this->user->data['user_id'] . '_');
// Are we uploading an image *and* this image being within the image category?
// Only then perform additional image checks.
$this->file->move_file($this->config['upload_path'], false, !$is_image);
// Do we have to create a thumbnail?
$this->file_data['thumbnail'] = ($is_image && $this->config['img_create_thumbnail']) ? 1 : 0;
// Make sure the image category only holds valid images...
$this->check_image($is_image);
if (count($this->file->error))
{
$this->file->remove();
$this->file_data['error'] = array_merge($this->file_data['error'], $this->file->error);
$this->file_data['post_attach'] = false;
return $this->file_data;
}
$this->fill_file_data();
$filedata = $this->file_data;
@@ -200,6 +192,19 @@ class upload
// Create Thumbnail
$this->create_thumbnail();
// Are we uploading an image *and* this image being within the image category?
// Only then perform additional image checks.
$this->file->move_file($this->storage, false, !$is_image);
if (count($this->file->error))
{
$this->file->remove($this->storage);
$this->file_data['error'] = array_merge($this->file_data['error'], $this->file->error);
$this->file_data['post_attach'] = false;
return $this->file_data;
}
return $this->file_data;
}
@@ -212,10 +217,18 @@ class upload
{
if ($this->file_data['thumbnail'])
{
$source = $this->file->get('destination_file');
$destination = $this->file->get('destination_path') . '/thumb_' . $this->file->get('realname');
$source = $this->file->get('filename');
$destination_name = 'thumb_' . $this->file->get('realname');
$destination = sys_get_temp_dir() . '/' . $destination_name;
if (!create_thumbnail($source, $destination, $this->file->get('mimetype')))
if (create_thumbnail($source, $destination, $this->file->get('mimetype')))
{
// Move the thumbnail from temp folder to the storage
$fp = fopen($destination, 'rb');
$this->storage->write_stream($destination_name, $fp);
fclose($fp);
}
else
{
$this->file_data['thumbnail'] = 0;
}
@@ -253,7 +266,7 @@ class upload
// Make sure the image category only holds valid images...
if ($is_image && !$this->file->is_image())
{
$this->file->remove();
$this->file->remove($this->storage);
if ($this->plupload && $this->plupload->is_active())
{