mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/13904] Use ini_get() wrapper in file upload types
PHPBB3-13904
This commit is contained in:
parent
16f3b8c2b9
commit
b29b62debe
7 changed files with 38 additions and 22 deletions
|
@ -35,6 +35,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @files.factory
|
- @files.factory
|
||||||
- @language
|
- @language
|
||||||
|
- @php_ini
|
||||||
- @plupload
|
- @plupload
|
||||||
- @request
|
- @request
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @files.factory
|
- @files.factory
|
||||||
- @language
|
- @language
|
||||||
|
- @php_ini
|
||||||
- @request
|
- @request
|
||||||
|
|
||||||
files.types.remote:
|
files.types.remote:
|
||||||
|
@ -52,5 +54,6 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @files.factory
|
- @files.factory
|
||||||
- @language
|
- @language
|
||||||
|
- @php_ini
|
||||||
- @request
|
- @request
|
||||||
- %core.root_path%
|
- %core.root_path%
|
||||||
|
|
|
@ -18,6 +18,9 @@ abstract class base implements type_interface
|
||||||
/** @var \phpbb\language\language */
|
/** @var \phpbb\language\language */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
|
/** @var \bantu\IniGetWrapper\IniGetWrapper */
|
||||||
|
protected $php_ini;
|
||||||
|
|
||||||
/** @var \phpbb\files\upload */
|
/** @var \phpbb\files\upload */
|
||||||
protected $upload;
|
protected $upload;
|
||||||
|
|
||||||
|
@ -33,7 +36,7 @@ abstract class base implements type_interface
|
||||||
// PHP Upload filesize exceeded
|
// PHP Upload filesize exceeded
|
||||||
if ($file->get('filename') == 'none')
|
if ($file->get('filename') == 'none')
|
||||||
{
|
{
|
||||||
$max_filesize = @ini_get('upload_max_filesize');
|
$max_filesize = $this->php_ini->getString('upload_max_filesize');
|
||||||
$unit = 'MB';
|
$unit = 'MB';
|
||||||
|
|
||||||
if (!empty($max_filesize))
|
if (!empty($max_filesize))
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
namespace phpbb\files\types;
|
namespace phpbb\files\types;
|
||||||
|
|
||||||
|
use \bantu\IniGetWrapper\IniGetWrapper;
|
||||||
use \phpbb\files\factory;
|
use \phpbb\files\factory;
|
||||||
use \phpbb\files\filespec;
|
use \phpbb\files\filespec;
|
||||||
use \phpbb\files\upload;
|
use \phpbb\files\upload;
|
||||||
|
@ -28,6 +29,9 @@ class form extends base
|
||||||
/** @var language */
|
/** @var language */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
|
/** @var IniGetWrapper */
|
||||||
|
protected $php_ini;
|
||||||
|
|
||||||
/** @var plupload */
|
/** @var plupload */
|
||||||
protected $plupload;
|
protected $plupload;
|
||||||
|
|
||||||
|
@ -42,13 +46,15 @@ class form extends base
|
||||||
*
|
*
|
||||||
* @param factory $factory Files factory
|
* @param factory $factory Files factory
|
||||||
* @param language $language Language class
|
* @param language $language Language class
|
||||||
|
* @param IniGetWrapper $php_ini ini_get() wrapper
|
||||||
* @param plupload $plupload Plupload
|
* @param plupload $plupload Plupload
|
||||||
* @param request_interface $request Request object
|
* @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->factory = $factory;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
|
$this->php_ini = $php_ini;
|
||||||
$this->plupload = $plupload;
|
$this->plupload = $plupload;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
namespace phpbb\files\types;
|
namespace phpbb\files\types;
|
||||||
|
|
||||||
|
use \bantu\IniGetWrapper\IniGetWrapper;
|
||||||
use \phpbb\files\factory;
|
use \phpbb\files\factory;
|
||||||
use \phpbb\files\filespec;
|
use \phpbb\files\filespec;
|
||||||
use \phpbb\language\language;
|
use \phpbb\language\language;
|
||||||
|
@ -26,6 +27,9 @@ class local extends base
|
||||||
/** @var language */
|
/** @var language */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
|
/** @var IniGetWrapper */
|
||||||
|
protected $php_ini;
|
||||||
|
|
||||||
/** @var request_interface */
|
/** @var request_interface */
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
|
@ -37,12 +41,14 @@ class local extends base
|
||||||
*
|
*
|
||||||
* @param factory $factory Files factory
|
* @param factory $factory Files factory
|
||||||
* @param language $language Language class
|
* @param language $language Language class
|
||||||
|
* @param IniGetWrapper $php_ini ini_get() wrapper
|
||||||
* @param request_interface $request Request object
|
* @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->factory = $factory;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
|
$this->php_ini = $php_ini;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,21 +95,11 @@ class local extends base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PHP Upload filesize exceeded
|
// PHP Upload file size check
|
||||||
if ($file->get('filename') == 'none')
|
$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;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
namespace phpbb\files\types;
|
namespace phpbb\files\types;
|
||||||
|
|
||||||
|
use \bantu\IniGetWrapper\IniGetWrapper;
|
||||||
use \phpbb\files\factory;
|
use \phpbb\files\factory;
|
||||||
use \phpbb\files\filespec;
|
use \phpbb\files\filespec;
|
||||||
use \phpbb\language\language;
|
use \phpbb\language\language;
|
||||||
|
@ -26,6 +27,9 @@ class remote extends base
|
||||||
/** @var language */
|
/** @var language */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
|
/** @var IniGetWrapper */
|
||||||
|
protected $php_ini;
|
||||||
|
|
||||||
/** @var request_interface */
|
/** @var request_interface */
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
|
@ -40,13 +44,15 @@ class remote extends base
|
||||||
*
|
*
|
||||||
* @param factory $factory Files factory
|
* @param factory $factory Files factory
|
||||||
* @param language $language Language class
|
* @param language $language Language class
|
||||||
|
* @param IniGetWrapper $php_ini ini_get() wrapper
|
||||||
* @param request_interface $request Request object
|
* @param request_interface $request Request object
|
||||||
* @param string $phpbb_root_path phpBB root path
|
* @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->factory = $factory;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
|
$this->php_ini = $php_ini;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$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');
|
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() . '-');
|
$filename = tempnam($tmp_path, unique_id() . '-');
|
||||||
|
|
||||||
if (!($fp = @fopen($filename, 'wb')))
|
if (!($fp = @fopen($filename, 'wb')))
|
||||||
|
@ -232,7 +238,7 @@ class remote extends base
|
||||||
$max_file_size = $this->upload->max_filesize;
|
$max_file_size = $this->upload->max_filesize;
|
||||||
if (!$max_file_size)
|
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))
|
if (!empty($max_filesize))
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,7 +60,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
|
||||||
$container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, $this->phpbb_root_path));
|
$container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, $this->phpbb_root_path));
|
||||||
$this->factory = new \phpbb\files\factory($container);
|
$this->factory = new \phpbb\files\factory($container);
|
||||||
$container->set('files.factory', $this->factory);
|
$container->set('files.factory', $this->factory);
|
||||||
$container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->request, $phpbb_root_path));
|
$container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->php_ini, $this->request, $phpbb_root_path));
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,12 +81,14 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||||
$this->container->set('files.types.form', new \phpbb\files\types\form(
|
$this->container->set('files.types.form', new \phpbb\files\types\form(
|
||||||
$this->factory,
|
$this->factory,
|
||||||
$this->language,
|
$this->language,
|
||||||
|
$this->php_ini,
|
||||||
$plupload,
|
$plupload,
|
||||||
$this->request
|
$this->request
|
||||||
), phpbb_mock_container_builder::SCOPE_PROTOTYPE);
|
), phpbb_mock_container_builder::SCOPE_PROTOTYPE);
|
||||||
$this->container->set('files.types.local', new \phpbb\files\types\local(
|
$this->container->set('files.types.local', new \phpbb\files\types\local(
|
||||||
$this->factory,
|
$this->factory,
|
||||||
$this->language,
|
$this->language,
|
||||||
|
$this->php_ini,
|
||||||
$this->request
|
$this->request
|
||||||
), phpbb_mock_container_builder::SCOPE_PROTOTYPE);
|
), phpbb_mock_container_builder::SCOPE_PROTOTYPE);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue