1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-11 11:13:59 +02:00

[ticket/13904] Fix minor issues and move local_upload to its own class

PHPBB3-13904
This commit is contained in:
Marc Alexander
2015-07-15 16:08:20 +02:00
parent cf9b6ed474
commit adcc901af1
6 changed files with 188 additions and 109 deletions

View File

@@ -199,86 +199,6 @@ class upload
return (is_object($type_class)) ? call_user_func_array(array($type_class, 'upload'), $args) : 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
*/
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