diff options
author | Marc Alexander <admin@m-a-styles.de> | 2015-08-27 12:48:06 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2015-09-09 08:29:06 +0200 |
commit | b29b62debe4077ec688ebee9e9363db2c8614dd5 (patch) | |
tree | ca58b0928b1dccf8d40dcd8c533f8830d9f4d855 /phpBB | |
parent | 16f3b8c2b9de388223cbe8ace9e1d9bcf0ba5e11 (diff) | |
download | forums-b29b62debe4077ec688ebee9e9363db2c8614dd5.tar forums-b29b62debe4077ec688ebee9e9363db2c8614dd5.tar.gz forums-b29b62debe4077ec688ebee9e9363db2c8614dd5.tar.bz2 forums-b29b62debe4077ec688ebee9e9363db2c8614dd5.tar.xz forums-b29b62debe4077ec688ebee9e9363db2c8614dd5.zip |
[ticket/13904] Use ini_get() wrapper in file upload types
PHPBB3-13904
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/config/default/container/services_files.yml | 3 | ||||
-rw-r--r-- | phpBB/phpbb/files/types/base.php | 5 | ||||
-rw-r--r-- | phpBB/phpbb/files/types/form.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/files/types/local.php | 26 | ||||
-rw-r--r-- | phpBB/phpbb/files/types/remote.php | 12 |
5 files changed, 35 insertions, 21 deletions
diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index 25cd532ae3..a4136a0573 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -35,6 +35,7 @@ services: arguments: - @files.factory - @language + - @php_ini - @plupload - @request @@ -44,6 +45,7 @@ services: arguments: - @files.factory - @language + - @php_ini - @request files.types.remote: @@ -52,5 +54,6 @@ services: arguments: - @files.factory - @language + - @php_ini - @request - %core.root_path% diff --git a/phpBB/phpbb/files/types/base.php b/phpBB/phpbb/files/types/base.php index 1ed06053a4..3313ad040b 100644 --- a/phpBB/phpbb/files/types/base.php +++ b/phpBB/phpbb/files/types/base.php @@ -18,6 +18,9 @@ abstract class base implements type_interface /** @var \phpbb\language\language */ protected $language; + /** @var \bantu\IniGetWrapper\IniGetWrapper */ + protected $php_ini; + /** @var \phpbb\files\upload */ protected $upload; @@ -33,7 +36,7 @@ abstract class base implements type_interface // PHP Upload filesize exceeded if ($file->get('filename') == 'none') { - $max_filesize = @ini_get('upload_max_filesize'); + $max_filesize = $this->php_ini->getString('upload_max_filesize'); $unit = 'MB'; if (!empty($max_filesize)) diff --git a/phpBB/phpbb/files/types/form.php b/phpBB/phpbb/files/types/form.php index be0a425d57..b8ad62f58b 100644 --- a/phpBB/phpbb/files/types/form.php +++ b/phpBB/phpbb/files/types/form.php @@ -13,6 +13,7 @@ namespace phpbb\files\types; +use \bantu\IniGetWrapper\IniGetWrapper; use \phpbb\files\factory; use \phpbb\files\filespec; use \phpbb\files\upload; @@ -28,6 +29,9 @@ class form extends base /** @var language */ protected $language; + /** @var IniGetWrapper */ + protected $php_ini; + /** @var plupload */ protected $plupload; @@ -42,13 +46,15 @@ class form extends base * * @param factory $factory Files factory * @param language $language Language class + * @param IniGetWrapper $php_ini ini_get() wrapper * @param plupload $plupload Plupload * @param request_interface $request Request object */ - public function __construct(factory $factory, language $language, plupload $plupload, request_interface $request) + public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request_interface $request) { $this->factory = $factory; $this->language = $language; + $this->php_ini = $php_ini; $this->plupload = $plupload; $this->request = $request; } @@ -122,7 +128,7 @@ class form extends base return $file; } - // PHP Upload filesize check + // PHP Upload file size check $file = $this->check_upload_size($file); if (sizeof($file->error)) { diff --git a/phpBB/phpbb/files/types/local.php b/phpBB/phpbb/files/types/local.php index dfaabded9b..96bfdaca7f 100644 --- a/phpBB/phpbb/files/types/local.php +++ b/phpBB/phpbb/files/types/local.php @@ -13,6 +13,7 @@ namespace phpbb\files\types; +use \bantu\IniGetWrapper\IniGetWrapper; use \phpbb\files\factory; use \phpbb\files\filespec; use \phpbb\language\language; @@ -26,6 +27,9 @@ class local extends base /** @var language */ protected $language; + /** @var IniGetWrapper */ + protected $php_ini; + /** @var request_interface */ protected $request; @@ -37,12 +41,14 @@ class local extends base * * @param factory $factory Files factory * @param language $language Language class + * @param IniGetWrapper $php_ini ini_get() wrapper * @param request_interface $request Request object */ - public function __construct(factory $factory, language $language, request_interface $request) + public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request) { $this->factory = $factory; $this->language = $language; + $this->php_ini = $php_ini; $this->request = $request; } @@ -89,21 +95,11 @@ class local extends base } } - // PHP Upload filesize exceeded - if ($file->get('filename') == 'none') + // PHP Upload file size check + $this->check_upload_size($file); + $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->upload->error_prefix . 'PHP_SIZE_NA') : $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, $this->language->lang($unit)); return $file; } diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php index 94bba8ad46..bad87243a5 100644 --- a/phpBB/phpbb/files/types/remote.php +++ b/phpBB/phpbb/files/types/remote.php @@ -13,6 +13,7 @@ namespace phpbb\files\types; +use \bantu\IniGetWrapper\IniGetWrapper; use \phpbb\files\factory; use \phpbb\files\filespec; use \phpbb\language\language; @@ -26,6 +27,9 @@ class remote extends base /** @var language */ protected $language; + /** @var IniGetWrapper */ + protected $php_ini; + /** @var request_interface */ protected $request; @@ -40,13 +44,15 @@ class remote extends base * * @param factory $factory Files factory * @param language $language Language class + * @param IniGetWrapper $php_ini ini_get() wrapper * @param request_interface $request Request object * @param string $phpbb_root_path phpBB root path */ - public function __construct(factory $factory, language $language, request_interface $request, $phpbb_root_path) + public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) { $this->factory = $factory; $this->language = $language; + $this->php_ini = $php_ini; $this->request = $request; $this->phpbb_root_path = $phpbb_root_path; } @@ -199,7 +205,7 @@ class remote extends base return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'EMPTY_REMOTE_DATA'); } - $tmp_path = (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') ? false : $this->phpbb_root_path . 'cache'; + $tmp_path = (!$this->php_ini->getBool('safe_mode')) ? false : $this->phpbb_root_path . 'cache'; $filename = tempnam($tmp_path, unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) @@ -232,7 +238,7 @@ class remote extends base $max_file_size = $this->upload->max_filesize; if (!$max_file_size) { - $max_file_size = @ini_get('upload_max_filesize'); + $max_file_size = $this->php_ini->getString('upload_max_filesize'); if (!empty($max_filesize)) { |