首頁  >  文章  >  後端開發  >  七牛 圖片上傳問題

七牛 圖片上傳問題

WBOY
WBOY原創
2016-09-08 08:44:001997瀏覽

在用七牛雲上傳圖片時,出現了以下錯誤
Fatal error: Uncaught exception 'Exception' with message 'file can not open' in /var/www/html/includes/src/Qiniu/Storage/UploadManager.php :91 Stack trace: #0 /var/www/html/includes/cls_image.php(150): QiniuStorageUploadManager->putFile('2kHh1HThkNyWvGL...', 'images/201609/g...', 'images/201609 /s...') #1 /var/www/html/admin/goods.php(1132): cls_image->qiniuUpload('images/201609/s...', 'goods_img') #2 {main} thrown in /var/www/html/includes/src/Qiniu/Storage/UploadManager.php on line 91

回覆內容:

在用七牛雲上傳圖片時,出現了以下錯誤
Fatal error: Uncaught exception 'Exception' with message 'file can not open' in /var/www/html/includes/src/Qiniu/Storage/UploadManager.php :91 Stack trace: #0 /var/www/html/includes/cls_image.php(150): QiniuStorageUploadManager->putFile('2kHh1HThkNyWvGL...', 'images/201609/g...', 'images/201609 /s...') #1 /var/www/html/admin/goods.php(1132): cls_image->qiniuUpload('images/201609/s...', 'goods_img') #2 {main} thrown in /var/www/html/includes/src/Qiniu/Storage/UploadManager.php on line 91

請確認上傳檔案的路徑是否有值。即

$_FILES['input-file-name']['tmp_name']

七牛雲代碼定位如下:

<code>public function putFile(
        $upToken,
        $key,
        $filePath,
        $params = null,
        $mime = 'application/octet-stream',
        $checkCrc = false
    ) {
        $file = fopen($filePath, 'rb'); //文件不存在,或者不可读
        if ($file === false) { //文件为空
            throw new \Exception("file can not open", 1); //抛出错误的地方
        }
        $params = self::trimParams($params);
        $stat = fstat($file);
        $size = $stat['size'];
        if ($size <= Config::BLOCK_SIZE) {
            $data = fread($file, $size);
            fclose($file);
            if ($data === false) {
                throw new \Exception("file can not read", 1);
            }
            return FormUploader::put(
                $upToken,
                $key,
                $data,
                $this->config,
                $params,
                $mime,
                $checkCrc
            );
        }
        $up = new ResumeUploader(
            $upToken,
            $key,
            $file,
            $size,
            $params,
            $mime,
            $this->config
        );
        $ret = $up->upload();
        fclose($file);
        return $ret;
    }</code>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn