本文整理汇总了PHP中upload_manager::save_file方法的典型用法代码示例。如果您正苦于以下问题:PHP upload_manager::save_file方法的具体用法?PHP upload_manager::save_file怎么用?PHP upload_manager::save_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类upload_manager
的用法示例。
在下文中一共展示了upload_manager::save_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_uploaded_file
/**
* Processes a newly uploaded file, copies it to disk, and creates
* a new artefact object.
* Takes the name of a file input.
* Returns false for no errors, or a string describing the error.
*/
public static function save_uploaded_file($inputname, $data)
{
require_once 'uploadmanager.php';
$um = new upload_manager($inputname);
if ($error = $um->preprocess_file()) {
throw new UploadException($error);
}
$size = $um->file['size'];
if (!empty($data->owner)) {
global $USER;
if ($data->owner == $USER->get('id')) {
$owner = $USER;
} else {
$owner = new User();
$owner->find_by_id($data->owner);
}
if (!$owner->quota_allowed($size)) {
throw new QuotaExceededException(get_string('uploadexceedsquota', 'artefact.file'));
}
}
$data->size = $size;
$data->filetype = $um->file['type'];
$data->oldextension = $um->original_filename_extension();
$f = self::new_file($um->file['tmp_name'], $data);
$f->commit();
$id = $f->get('id');
// Save the file using its id as the filename, and use its id modulo
// the number of subdirectories as the directory name.
if ($error = $um->save_file(self::get_file_directory($id), $id)) {
$f->delete();
throw new UploadException($error);
} else {
if ($owner) {
$owner->quota_add($size);
$owner->commit();
}
}
return $id;
}