aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2015-07-15 16:08:20 +0200
committerMarc Alexander <admin@m-a-styles.de>2015-09-09 08:27:58 +0200
commitadcc901af181b6727dd7af89a3926c9923a58471 (patch)
tree720561f2a804e91717124607c5a4e8701336b13d /phpBB/phpbb/files
parent[ticket/13904] Use the class member plupload instead of argument (diff)
downloadphpbb-adcc901af181b6727dd7af89a3926c9923a58471.tar.gz
phpbb-adcc901af181b6727dd7af89a3926c9923a58471.tar.bz2
phpbb-adcc901af181b6727dd7af89a3926c9923a58471.zip
[ticket/13904] Fix minor issues and move local_upload to its own class
PHPBB3-13904
Diffstat (limited to 'phpBB/phpbb/files')
-rw-r--r--phpBB/phpbb/files/types/form.php39
-rw-r--r--phpBB/phpbb/files/types/local.php137
-rw-r--r--phpBB/phpbb/files/upload.php80
3 files changed, 152 insertions, 104 deletions
diff --git a/phpBB/phpbb/files/types/form.php b/phpBB/phpbb/files/types/form.php
index 130a64445b..98d1c51d5f 100644
--- a/phpBB/phpbb/files/types/form.php
+++ b/phpBB/phpbb/files/types/form.php
@@ -16,14 +16,18 @@ namespace phpbb\files\types;
use \phpbb\files\factory;
use \phpbb\files\filespec;
use \phpbb\files\upload;
+use \phpbb\language\language;
use \phpbb\plupload\plupload;
use \phpbb\request\request_interface;
-class form implements type_interface
+class form extends base
{
/** @var factory Files factory */
protected $factory;
+ /** @var language */
+ protected $language;
+
/** @var plupload */
protected $plupload;
@@ -39,9 +43,10 @@ class form implements type_interface
* @param factory $factory
* @param request_interface $request
*/
- public function __construct(factory $factory, plupload $plupload, request_interface $request)
+ public function __construct(factory $factory, language $language, plupload $plupload, request_interface $request)
{
$this->factory = $factory;
+ $this->language = $language;
$this->plupload = $plupload;
$this->request = $request;
}
@@ -79,13 +84,10 @@ class form implements type_interface
$upload = $this->request->file($form_name);
unset($upload['local_mode']);
- if ($this->plupload)
+ $result = $this->plupload->handle_upload($form_name);
+ if (is_array($result))
{
- $result = $this->plupload->handle_upload($form_name);
- if (is_array($result))
- {
- $upload = array_merge($upload, $result);
- }
+ $upload = array_merge($upload, $result);
}
/** @var filespec $file */
@@ -114,32 +116,21 @@ class form implements type_interface
// Check if empty file got uploaded (not catched by is_uploaded_file)
if (isset($upload['size']) && $upload['size'] == 0)
{
- $file->error[] = $this->language->lang($this->error_prefix . 'EMPTY_FILEUPLOAD');
+ $file->error[] = $this->language->lang($this->upload->error_prefix . 'EMPTY_FILEUPLOAD');
return $file;
}
- // PHP Upload filesize exceeded
- if ($file->get('filename') == 'none')
+ // PHP Upload filesize check
+ $file = $this->check_upload_size($file);
+ if (sizeof($file->error))
{
- $max_filesize = @ini_get('upload_max_filesize');
- $unit = 'MB';
-
- if (!empty($max_filesize))
- {
- $unit = strtolower(substr($max_filesize, -1, 1));
- $max_filesize = (int) $max_filesize;
-
- $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
- }
-
- $file->error[] = (empty($max_filesize)) ? $this->language->lang($this->error_prefix . 'PHP_SIZE_NA') : $this->language->lang($this->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, $this->language->lang($unit));
return $file;
}
// Not correctly uploaded
if (!$file->is_uploaded())
{
- $file->error[] = $this->language->lang($this->error_prefix . 'NOT_UPLOADED');
+ $file->error[] = $this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED');
return $file;
}
diff --git a/phpBB/phpbb/files/types/local.php b/phpBB/phpbb/files/types/local.php
new file mode 100644
index 0000000000..38876d8ab4
--- /dev/null
+++ b/phpBB/phpbb/files/types/local.php
@@ -0,0 +1,137 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\files\types;
+
+use \phpbb\files\factory;
+use \phpbb\files\filespec;
+use \phpbb\files\upload;
+use \phpbb\language\language;
+use \phpbb\request\request_interface;
+
+class local extends base
+{
+ /** @var factory Files factory */
+ protected $factory;
+
+ /** @var language */
+ protected $language;
+
+ /** @var request_interface */
+ protected $request;
+
+ /** @var upload */
+ protected $upload;
+
+ /**
+ * Construct a form upload type
+ *
+ * @param factory $factory
+ * @param request_interface $request
+ */
+ public function __construct(factory $factory, language $language, request_interface $request)
+ {
+ $this->factory = $factory;
+ $this->language = $language;
+ $this->request = $request;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function upload()
+ {
+ $args = func_get_args();
+ return $this->local_upload($args[0], isset($args[1]) ? $args[1] : false);
+ }
+
+ /**
+ * Move file from another location to phpBB
+ *
+ * @param string $source_file Filename of source file
+ * @param array|bool $filedata Array with filedata or false
+ *
+ * @return filespec Object "filespec" is returned, all further operations can be done with this object
+ */
+ protected function local_upload($source_file, $filedata = false)
+ {
+ $upload = array();
+
+ $upload['local_mode'] = true;
+ $upload['tmp_name'] = $source_file;
+
+ if ($filedata === false)
+ {
+ $upload['name'] = utf8_basename($source_file);
+ $upload['size'] = 0;
+ }
+ else
+ {
+ $upload['name'] = $filedata['realname'];
+ $upload['size'] = $filedata['size'];
+ $upload['type'] = $filedata['type'];
+ }
+
+ /** @var filespec $file */
+ $file = $this->factory->get('filespec')
+ ->set_upload_ary($upload)
+ ->set_upload_namespace($this->upload);
+
+ if ($file->init_error())
+ {
+ $file->error[] = '';
+ return $file;
+ }
+
+ if (isset($upload['error']))
+ {
+ $error = $this->upload->assign_internal_error($upload['error']);
+
+ if ($error !== false)
+ {
+ $file->error[] = $error;
+ return $file;
+ }
+ }
+
+ // PHP Upload filesize exceeded
+ if ($file->get('filename') == 'none')
+ {
+ $max_filesize = @ini_get('upload_max_filesize');
+ $unit = 'MB';
+
+ if (!empty($max_filesize))
+ {
+ $unit = strtolower(substr($max_filesize, -1, 1));
+ $max_filesize = (int) $max_filesize;
+
+ $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
+ }
+
+ $file->error[] = (empty($max_filesize)) ?$this->language->lang($this->upload->error_prefix . 'PHP_SIZE_NA') : $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, $this->language->lang($unit));
+ return $file;
+ }
+
+ // Not correctly uploaded
+ if (!$file->is_uploaded())
+ {
+ $file->error[] = $this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED');
+ return $file;
+ }
+
+ $this->upload->common_checks($file);
+ $this->request->overwrite('local', $upload, request_interface::FILES);
+
+ return $file;
+ }
+}
diff --git a/phpBB/phpbb/files/upload.php b/phpBB/phpbb/files/upload.php
index 09f2b9408d..471c9c378f 100644
--- a/phpBB/phpbb/files/upload.php
+++ b/phpBB/phpbb/files/upload.php
@@ -200,86 +200,6 @@ class upload
}
/**
- * Move file from another location to phpBB
- *
- * @param string $source_file Filename of source file
- * @param array|bool $filedata Array with filedata or false
- *
- * @return filespec Object "filespec" is returned, all further operations can be done with this object
- */
- function local_upload($source_file, $filedata = false)
- {
- $upload = array();
-
- $upload['local_mode'] = true;
- $upload['tmp_name'] = $source_file;
-
- if ($filedata === false)
- {
- $upload['name'] = utf8_basename($source_file);
- $upload['size'] = 0;
- }
- else
- {
- $upload['name'] = $filedata['realname'];
- $upload['size'] = $filedata['size'];
- $upload['type'] = $filedata['type'];
- }
-
- /** @var filespec $file */
- $file = $this->factory->get('filespec')
- ->set_upload_ary($upload)
- ->set_upload_namespace($this);
-
- if ($file->init_error())
- {
- $file->error[] = '';
- return $file;
- }
-
- if (isset($upload['error']))
- {
- $error = $this->assign_internal_error($upload['error']);
-
- if ($error !== false)
- {
- $file->error[] = $error;
- return $file;
- }
- }
-
- // PHP Upload filesize exceeded
- if ($file->get('filename') == 'none')
- {
- $max_filesize = @ini_get('upload_max_filesize');
- $unit = 'MB';
-
- if (!empty($max_filesize))
- {
- $unit = strtolower(substr($max_filesize, -1, 1));
- $max_filesize = (int) $max_filesize;
-
- $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
- }
-
- $file->error[] = (empty($max_filesize)) ?$this->language->lang($this->error_prefix . 'PHP_SIZE_NA') : $this->language->lang($this->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, $this->language->lang($unit));
- return $file;
- }
-
- // Not correctly uploaded
- if (!$file->is_uploaded())
- {
- $file->error[] = $this->language->lang($this->error_prefix . 'NOT_UPLOADED');
- return $file;
- }
-
- $this->common_checks($file);
- $this->request->overwrite('local', $upload, request_interface::FILES);
-
- return $file;
- }
-
- /**
* Remote upload method
* Uploads file from given url
*