• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP file_get_upload_error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中file_get_upload_error函数的典型用法代码示例。如果您正苦于以下问题:PHP file_get_upload_error函数的具体用法?PHP file_get_upload_error怎么用?PHP file_get_upload_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了file_get_upload_error函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: _validate_files

 /**
  * Internal method. Validates all old-style deprecated uploaded files.
  * The new way is to upload files via repository api.
  *
  * @param array $files list of files to be validated
  * @return bool|array Success or an array of errors
  */
 function _validate_files(&$files)
 {
     global $CFG, $COURSE;
     $files = array();
     if (empty($_FILES)) {
         // we do not need to do any checks because no files were submitted
         // note: server side rules do not work for files - use custom verification in validate() instead
         return true;
     }
     $errors = array();
     $filenames = array();
     // now check that we really want each file
     foreach ($_FILES as $elname => $file) {
         $required = $this->_form->isElementRequired($elname);
         if ($file['error'] == 4 and $file['size'] == 0) {
             if ($required) {
                 $errors[$elname] = get_string('required');
             }
             unset($_FILES[$elname]);
             continue;
         }
         if (!empty($file['error'])) {
             $errors[$elname] = file_get_upload_error($file['error']);
             unset($_FILES[$elname]);
             continue;
         }
         if (!is_uploaded_file($file['tmp_name'])) {
             // TODO: improve error message
             $errors[$elname] = get_string('error');
             unset($_FILES[$elname]);
             continue;
         }
         if (!$this->_form->elementExists($elname) or !$this->_form->getElementType($elname) == 'file') {
             // hmm, this file was not requested
             unset($_FILES[$elname]);
             continue;
         }
         // NOTE: the viruses are scanned in file picker, no need to deal with them here.
         $filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
         if ($filename === '') {
             // TODO: improve error message - wrong chars
             $errors[$elname] = get_string('error');
             unset($_FILES[$elname]);
             continue;
         }
         if (in_array($filename, $filenames)) {
             // TODO: improve error message - duplicate name
             $errors[$elname] = get_string('error');
             unset($_FILES[$elname]);
             continue;
         }
         $filenames[] = $filename;
         $_FILES[$elname]['name'] = $filename;
         $files[$elname] = $_FILES[$elname]['tmp_name'];
     }
     // return errors if found
     if (count($errors) == 0) {
         return true;
     } else {
         $files = array();
         return $errors;
     }
 }
开发者ID:educacionbe,项目名称:cursos,代码行数:70,代码来源:formslib.php


示例2: foreach

foreach ($files as $hash => $file) {
    if (!$subdirs and $file->get_filepath() !== '/') {
        unset($files[$hash]);
        continue;
    }
    $totalbytes += $file->get_filesize();
}
/// process actions
if ($newdirname !== '' and data_submitted() and confirm_sesskey()) {
    $newdirname = $directory->get_filepath() . $newdirname . '/';
    $fs->create_directory($contextid, $filearea, $itemid, $newdirname, $USER->id);
    redirect('draftfiles.php?itemid=' . $itemid . '&filepath=' . rawurlencode($newdirname) . '&subdirs=' . $subdirs . '&maxbytes=' . $maxbytes);
}
if (isset($_FILES['newfile']) and data_submitted() and confirm_sesskey()) {
    if (!empty($_FILES['newfile']['error'])) {
        $notice = file_get_upload_error($_FILES['newfile']['error']);
    } else {
        $file = $_FILES['newfile'];
        $newfilename = clean_param($file['name'], PARAM_FILE);
        if (is_uploaded_file($_FILES['newfile']['tmp_name'])) {
            if ($existingfile = $fs->get_file($contextid, $filearea, $itemid, $filepath, $newfilename)) {
                $existingfile->delete();
            }
            $filerecord = array('contextid' => $contextid, 'filearea' => $filearea, 'itemid' => $itemid, 'filepath' => $filepath, 'filename' => $newfilename, 'userid' => $USER->id);
            $newfile = $fs->create_file_from_pathname($filerecord, $_FILES['newfile']['tmp_name']);
            redirect('draftfiles.php?itemid=' . $itemid . '&filepath=' . rawurlencode($filepath) . '&subdirs=' . $subdirs . '&maxbytes=' . $maxbytes);
        }
    }
}
if ($delete !== '' and $file = $fs->get_file($contextid, $filearea, $itemid, $filepath, $delete)) {
    if (!data_submitted() or !confirm_sesskey()) {
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:draftfiles.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP file_get_visible_attachments函数代码示例发布时间:2022-05-15
下一篇:
PHP file_get_unused_draft_itemid函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap