mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/13904] Split code up and pass root path to remote upload type
PHPBB3-13904
This commit is contained in:
parent
0a6f54d522
commit
a09c6d1fb7
3 changed files with 43 additions and 26 deletions
|
@ -51,3 +51,4 @@ services:
|
||||||
- @files.factory
|
- @files.factory
|
||||||
- @language
|
- @language
|
||||||
- @request
|
- @request
|
||||||
|
- %core.root_path%
|
||||||
|
|
|
@ -32,17 +32,21 @@ class remote extends base
|
||||||
/** @var \phpbb\files\upload */
|
/** @var \phpbb\files\upload */
|
||||||
protected $upload;
|
protected $upload;
|
||||||
|
|
||||||
|
/** @var string phpBB root path */
|
||||||
|
protected $phpbb_root_path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a form upload type
|
* Construct a form upload type
|
||||||
*
|
*
|
||||||
* @param factory $factory
|
* @param factory $factory
|
||||||
* @param request_interface $request
|
* @param request_interface $request
|
||||||
*/
|
*/
|
||||||
public function __construct(factory $factory, language $language, request_interface $request)
|
public function __construct(factory $factory, language $language, request_interface $request, $phpbb_root_path)
|
||||||
{
|
{
|
||||||
$this->factory = $factory;
|
$this->factory = $factory;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,30 +97,7 @@ class remote extends base
|
||||||
$filename = $url['path'];
|
$filename = $url['path'];
|
||||||
$filesize = 0;
|
$filesize = 0;
|
||||||
|
|
||||||
$remote_max_filesize = $this->upload->max_filesize;
|
$remote_max_filesize = $this->get_max_file_size();
|
||||||
if (!$remote_max_filesize)
|
|
||||||
{
|
|
||||||
$max_filesize = @ini_get('upload_max_filesize');
|
|
||||||
|
|
||||||
if (!empty($max_filesize))
|
|
||||||
{
|
|
||||||
$unit = strtolower(substr($max_filesize, -1, 1));
|
|
||||||
$remote_max_filesize = (int) $max_filesize;
|
|
||||||
|
|
||||||
switch ($unit)
|
|
||||||
{
|
|
||||||
case 'g':
|
|
||||||
$remote_max_filesize *= 1024;
|
|
||||||
// no break
|
|
||||||
case 'm':
|
|
||||||
$remote_max_filesize *= 1024;
|
|
||||||
// no break
|
|
||||||
case 'k':
|
|
||||||
$remote_max_filesize *= 1024;
|
|
||||||
// no break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$errno = 0;
|
$errno = 0;
|
||||||
$errstr = '';
|
$errstr = '';
|
||||||
|
@ -238,4 +219,39 @@ class remote extends base
|
||||||
|
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get maximum file size for remote uploads
|
||||||
|
*
|
||||||
|
* @return int Maximum file size
|
||||||
|
*/
|
||||||
|
protected function get_max_file_size()
|
||||||
|
{
|
||||||
|
$max_file_size = $this->upload->max_filesize;
|
||||||
|
if (!$max_file_size)
|
||||||
|
{
|
||||||
|
$max_file_size = @ini_get('upload_max_filesize');
|
||||||
|
|
||||||
|
if (!empty($max_filesize))
|
||||||
|
{
|
||||||
|
$unit = strtolower(substr($max_file_size, -1, 1));
|
||||||
|
$max_file_size = (int) $max_filesize;
|
||||||
|
|
||||||
|
switch ($unit)
|
||||||
|
{
|
||||||
|
case 'g':
|
||||||
|
$max_file_size *= 1024;
|
||||||
|
// no break
|
||||||
|
case 'm':
|
||||||
|
$max_file_size *= 1024;
|
||||||
|
// no break
|
||||||
|
case 'k':
|
||||||
|
$max_file_size *= 1024;
|
||||||
|
// no break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $max_file_size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,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->phpbb_root_path));
|
$container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $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));
|
$container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->request, $phpbb_root_path));
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue