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


PHP Upload::error方法代码示例

本文整理汇总了PHP中Upload::error方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::error方法的具体用法?PHP Upload::error怎么用?PHP Upload::error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Upload的用法示例。


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

示例1: replace

 public function replace($id = null)
 {
     if (!get('_csrf') or !csrf(get('_csrf'))) {
         return response::error('unauthenticated access');
     }
     $filename = get('filename');
     $file = $this->file($id, $filename);
     $blueprint = blueprint::find($this->page($id));
     $upload = new Upload($file->root(), array('overwrite' => true, 'accept' => function ($upload) use($file) {
         if ($upload->mime() != $file->mime()) {
             throw new Error(l('files.replace.error.type'));
         }
     }));
     if ($file = $upload->file()) {
         try {
             $this->checkUpload($file, $blueprint);
             kirby()->trigger('panel.file.replace', $file);
             return response::success('success');
         } catch (Exception $e) {
             $file->delete();
             return response::error($e->getMessage());
         }
     } else {
         return response::error($upload->error()->getMessage());
     }
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:26,代码来源:files.php

示例2: upload

 public function upload($username)
 {
     if (!get('_csrf') or !csrf(get('_csrf'))) {
         return response::error('unauthenticated access');
     }
     $user = $this->user($username);
     if (!$user) {
         return response::error(l('users.avatar.error.missing'));
     }
     if (!site()->user()->isAdmin() and !$user->isCurrent()) {
         return response::error('You are not allowed to upload an avatar for this user');
     }
     $root = $user->avatar() ? $user->avatar()->root() : $user->avatarRoot('{safeExtension}');
     $upload = new Upload($root, array('accept' => function ($upload) {
         if ($upload->type() != 'image') {
             throw new Error(l('users.avatar.error.type'));
         }
     }));
     if ($upload->file()) {
         thumb::$defaults['root'] = dirname($upload->file()->root());
         $thumb = new Thumb($upload->file(), array('filename' => $upload->file()->filename(), 'overwrite' => true, 'width' => 256, 'height' => 256, 'crop' => true));
         kirby()->trigger('panel.avatar.upload', $user->avatar());
         return response::success(l('users.avatar.success'));
     } else {
         return response::error($upload->error()->getMessage());
     }
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:27,代码来源:avatars.php

示例3: uploadSingle

 public static function uploadSingle($file, $path, $allow, $max_size = 1000000)
 {
     //判断文件的合法性
     if (!is_array($file) || count($file) != 5) {
         //错误
         self::$error = '上传文件不存在!';
         return false;
     }
     //判断错误代码
     switch ($file['error']) {
         case 1:
             //文件超过服务器允许大小
             self::$error = '文件超过服务器允许的大小,服务器允许的最大值为:' . ini_get('upload_max_filesize');
             return false;
         case 2:
             //文件超过表单允许大小
             self::$error = '文件超过表单允许大小!';
             return false;
         case 3:
             //文件只上传一部分
             self::$error = '文件只上传部分!';
             return false;
         case 4:
             //没有选中要上传的文件
             self::$error = '没有选中要上传的文件';
             return false;
         case 6:
         case 7:
             self::$error = '服务器错误,文件上传失败!';
             return false;
     }
     //判断文件类型是否符合
     if (strpos($allow, $file['type']) === false) {
         //没有匹配到:不允许的类型
         self::$error = '不允许的文件类型:允许的类型有:' . $allow;
         return false;
     }
     //文件大小判断
     if ($file['size'] > $max_size) {
         self::$error = '文件超出当前允许的大小:当前允许的大小为:' . $max_size / 1000000 . 'M';
         return false;
     }
     //移动文件到指定目录
     $new_name = self::getNewName($file['name']);
     if (move_uploaded_file($file['tmp_name'], $path . '/' . $new_name)) {
         //文件移动成功
         return $new_name;
     } else {
         //失败
         self::$error = '文件移动失败!';
         return false;
     }
 }
开发者ID:OldMo,项目名称:DaoGou,代码行数:53,代码来源:Upload.class.php

示例4: replace

 public function replace($id)
 {
     $filename = get('filename');
     $file = $this->file($id, $filename);
     $upload = new Upload($file->root(), array('overwrite' => true, 'accept' => function ($upload) use($file) {
         if ($upload->mime() != $file->mime()) {
             throw new Error(l('files.replace.error.type'));
         }
     }));
     if ($upload->file()) {
         return response::success('success');
     } else {
         return response::error($upload->error()->getMessage());
     }
 }
开发者ID:kompuser,项目名称:panel,代码行数:15,代码来源:files.php

示例5: upload

 public function upload($username)
 {
     $user = $this->user($username);
     if (!$user) {
         return response::error(l('users.avatar.error.missing'));
     }
     $root = $user->avatar() ? $user->avatar()->root() : $user->avatarRoot('{safeExtension}');
     $upload = new Upload($root, array('accept' => function ($upload) {
         if ($upload->type() != 'image') {
             throw new Error(l('users.avatar.error.type'));
         }
     }));
     if ($upload->file()) {
         thumb::$defaults['root'] = dirname($upload->file()->root());
         thumb::$defaults['driver'] = 'im';
         $thumb = new Thumb($upload->file(), array('filename' => $upload->file()->filename(), 'overwrite' => true, 'width' => 256, 'height' => 256, 'crop' => true));
         return response::success(l('users.avatar.success'));
     } else {
         return response::error($upload->error()->getMessage());
     }
 }
开发者ID:kompuser,项目名称:panel,代码行数:21,代码来源:avatars.php

示例6: Upload

        $upload = new Upload();
        $upload->set_max_size(1800000);
        $upload->set_directory($filedirectory);
        $upload->set_tmp_name($_FILES['backupfile']['tmp_name']);
        $upload->set_file_size($_FILES['backupfile']['size']);
        $upload->set_file_ext($_FILES['backupfile']['name']);
        $upload->set_file_type($filetype);
        $upload->set_file_name($filename);
        $upload->start_copy();
        if ($upload->is_ok()) {
            $restore = new iam_restore($upload->user_full_name, $cfg_db_host, $cfg_db_name, $cfg_db_user, $cfg_db_pass);
            $restore->perform_restore();
            unlink($upload->user_full_name);
            ShowMsg("数据恢复成功");
        } else {
            ShowMsg($upload->error());
            exit;
        }
    }
}
$adminpagetitle = "数据恢复";
include "admin.header.php";
?>
<div class="main_body">
<form action="dbrestore.php" method="post" enctype="multipart/form-data">
<table class="inputform" cellpadding="1" cellspacing="1">
<tr><td class="label">注意事项</td><td class="input">请选择已经备份的数据,上传后执行!</td></tr>
<tr><td class="label">备份文件</td><td class="input"><input type="file" name="backupfile" /></td></tr>
<tr><td class="label"></td><td class="input">
<input type="hidden" name="action" value="restore" />
<input type="submit" class="subtn" value="马上恢复" /></td></tr>
开发者ID:Fengtalk,项目名称:yiqicms,代码行数:31,代码来源:dbrestore.php

示例7: set_error

 /**
  * 设置错误信息
  *
  * @param string $error_msg
  * @param number $error_no
  * @return Upload
  */
 protected static function set_error($error_msg, $error_no = 0)
 {
     Upload::$errno = $error_msg;
     Upload::$error = $error_msg;
 }
开发者ID:xiaodin1,项目名称:myqee,代码行数:12,代码来源:upload.class.php


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