/** * Move file from another location to phpBB */ function local_upload($source_file, $filedata = false) { global $user; $form_name = 'local'; $_FILES[$form_name]['local_mode'] = true; $_FILES[$form_name]['tmp_name'] = $source_file; if ($filedata === false) { $_FILES[$form_name]['name'] = utf8_basename($source_file); $_FILES[$form_name]['size'] = 0; $mimetype = ''; if (function_exists('mime_content_type')) { $mimetype = mime_content_type($source_file); } // Some browsers choke on a mimetype of application/octet-stream if (!$mimetype || $mimetype == 'application/octet-stream') { $mimetype = 'application/octetstream'; } $_FILES[$form_name]['type'] = $mimetype; } else { $_FILES[$form_name]['name'] = $filedata['realname']; $_FILES[$form_name]['size'] = $filedata['size']; $_FILES[$form_name]['type'] = $filedata['type']; } $file = new filespec($_FILES[$form_name], $this); if ($file->init_error) { $file->error[] = ''; return $file; } if (isset($_FILES[$form_name]['error'])) { $error = $this->assign_internal_error($_FILES[$form_name]['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) ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], $max_filesize, $user->lang[$unit]); return $file; } // Not correctly uploaded if (!$file->is_uploaded()) { $file->error[] = $user->lang[$this->error_prefix . 'NOT_UPLOADED']; return $file; } $this->common_checks($file); return $file; }
/** * Move file from another location to phpBB */ function local_upload($source_file, $filedata = false, \phpbb\mimetype\guesser $mimetype_guesser = null) { global $user, $request; $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']; } $file = new filespec($upload, $this, $mimetype_guesser); 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) ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], $max_filesize, $user->lang[$unit]); return $file; } // Not correctly uploaded if (!$file->is_uploaded()) { $file->error[] = $user->lang[$this->error_prefix . 'NOT_UPLOADED']; return $file; } $this->common_checks($file); $request->overwrite('local', $upload, \phpbb\request\request_interface::FILES); return $file; }
function local_upload($source_file, $filedata = false) { global $_CLASS; $form_name = 'local'; $_FILES[$form_name]['local_mode'] = true; $_FILES[$form_name]['tmp_name'] = $source_file; if ($filedata === false) { $_FILES[$form_name]['name'] = basename($source_file); $_FILES[$form_name]['size'] = 0; $_FILES[$form_name]['type'] = ''; } else { $_FILES[$form_name]['name'] = $filedata['realname']; $_FILES[$form_name]['size'] = $filedata['size']; $_FILES[$form_name]['type'] = $filedata['type']; } $file = new filespec($_FILES[$form_name], $this); if ($file->init_error) { $file->error[] = ''; return $file; } if (isset($_FILES[$form_name]['error'])) { $error = $this->assign_internal_error($_FILES[$form_name]['error']); if ($error !== false) { $file->error[] = $error; return $file; } } // PHP Upload filesize exceeded if ($file->get('filename') == 'none') { $file->error[] = @ini_get('upload_max_filesize') == '' ? $_CLASS['core_user']->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($_CLASS['core_user']->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], @ini_get('upload_max_filesize')); return $file; } // Not correctly uploaded if (!$file->is_uploaded()) { $file->error[] = $_CLASS['core_user']->lang[$this->error_prefix . 'NOT_UPLOADED']; return $file; } $this->common_checks($file); return $file; }
/** * Form upload method * Upload file from users harddisk * * @param string $form_name Form name assigned to the file input field (if it is an array, the key has to be specified) * @return object $file Object "filespec" is returned, all further operations can be done with this object * @access public */ function form_upload($form_name) { global $user; unset($_FILES[$form_name]['local_mode']); $file = new filespec($_FILES[$form_name], $this); if ($file->init_error) { $file->error[] = ''; return $file; } // Error array filled? if (isset($_FILES[$form_name]['error'])) { $error = $this->assign_internal_error($_FILES[$form_name]['error']); if ($error !== false) { $file->error[] = $error; return $file; } } // Check if empty file got uploaded (not catched by is_uploaded_file) if (isset($_FILES[$form_name]['size']) && $_FILES[$form_name]['size'] == 0) { $file->error[] = $user->lang[$this->error_prefix . 'EMPTY_FILEUPLOAD']; return $file; } // PHP Upload filesize exceeded if ($file->get('filename') == 'none') { $file->error[] = (@ini_get('upload_max_filesize') == '') ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], @ini_get('upload_max_filesize')); return $file; } // Not correctly uploaded if (!$file->is_uploaded()) { $file->error[] = $user->lang[$this->error_prefix . 'NOT_UPLOADED']; return $file; } $this->common_checks($file); return $file; }