当前位置:Gxlcms > PHP教程 > 七牛图片上传问题

七牛图片上传问题

时间:2021-07-01 10:21:17 帮助过:2人阅读

在用七牛云上传图片时,出现了以下错误
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']

七牛云代码定位如下:

  1. <code>public function putFile(
  2. $upToken,
  3. $key,
  4. $filePath,
  5. $params = null,
  6. $mime = 'application/octet-stream',
  7. $checkCrc = false
  8. ) {
  9. $file = fopen($filePath, 'rb'); //文件不存在,或者不可读
  10. if ($file === false) { //文件为空
  11. throw new \Exception("file can not open", 1); //抛出错误的地方
  12. }
  13. $params = self::trimParams($params);
  14. $stat = fstat($file);
  15. $size = $stat['size'];
  16. if ($size <= Config::BLOCK_SIZE) {
  17. $data = fread($file, $size);
  18. fclose($file);
  19. if ($data === false) {
  20. throw new \Exception("file can not read", 1);
  21. }
  22. return FormUploader::put(
  23. $upToken,
  24. $key,
  25. $data,
  26. $this->config,
  27. $params,
  28. $mime,
  29. $checkCrc
  30. );
  31. }
  32. $up = new ResumeUploader(
  33. $upToken,
  34. $key,
  35. $file,
  36. $size,
  37. $params,
  38. $mime,
  39. $this->config
  40. );
  41. $ret = $up->upload();
  42. fclose($file);
  43. return $ret;
  44. }</code>

人气教程排行