当前位置: 首页>>代码示例>>PHP>>正文


PHP upload_manager::save_file方法代码示例

本文整理汇总了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;
 }
开发者ID:Br3nda,项目名称:mahara,代码行数:45,代码来源:lib.php


注:本文中的upload_manager::save_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。