【问题标题】:uncaught exception: could not open file未捕获的异常:无法打开文件
【发布时间】:2016-12-17 23:46:11
【问题描述】:

所以我正在尝试上传到 uploadcare cdn,但我收到此错误:未捕获的异常:无法打开文件“ce3577f708f527ff570e0d21acb39c62.jpg”

$description = $_POST['uploaddesc'];
  list($width,$height) = getimagesize($_FILES['uploadimage']['tmp_name']);
 $extensions  = array('image/jpeg','image/jpg','image/gif', 'image/png', 'image/tiff');
 $move = 'uploads/';
 $finfo = finfo_open(FILEINFO_MIME_TYPE);


$extension = pathinfo($_FILES['uploadimage']['name']);
if(!$_FILES['uploadimage']['tmp_name']){
$errors[]="Please choose an image";
}
if(empty($description)){
    $errors[]='Please choose a description for the image';
}
//IF IMAGE IS UPLOADED..
if($_FILES['uploadimage']['tmp_name']){
    $mime = finfo_file($finfo, $_FILES['uploadimage']['tmp_name']);

// 如果 MIME FAILES 或 GETIMAGESIZE 为 NULL(意味着它不是图像) if(!getimagesize($_FILES['uploadimage']['tmp_name']) && !in_array($_FILES['uploadimage']['tmp_name'],$mime)){ $errors[]='请选择一张图片'; 未设置($_FILES['uploadimage']['tmp_name']); }

     if(empty($errors)){

 $randString = md5(time()); //encode the timestamp - returns a 32 chars long string
 $fileName = $_FILES["uploadimage"]["name"]; //the original file name
 $splitName = explode(".", $fileName); //split the file name by the dot
 $fileExt = end($splitName); //get the file extension
 $newFileName  = strtolower($randString.'.'.$fileExt); //join file name and ext.
 if(move_uploaded_file($_FILES['uploadimage']['tmp_name'], $move . $newFileName)){
 $description = $_POST['uploaddesc']; 
 $user->insertArt($description, 'uploads/' . $newFileName, $user->getUsername($_SESSION['username']));
 $file = $api->uploader->fromPath('uploads/' . $newFileName);
 $file->store();    

//throw new ErrorException('MEMORY USAGE ' . memory_get_peak_usage());


 }
     }

}

【问题讨论】:

  • 那么,你的问题是什么?
  • 为什么会出现这个错误
  • 这个错误是指代码中的什么地方?什么线?您是否确保上传时使用的任何功能都不需要满足任何要求?比如文件名长度?
  • 错误似乎来自uploadcare uploader.php?私有函数 __runRequest($ch) { $data = curl_exec($ch); $ch_info = curl_getinfo($ch); if ($data === false) { throw new \Exception(curl_error($ch)); }
  • 所以这是一个 curl.. 错误?

标签: php uploadcare


【解决方案1】:

我已经修好了。我不得不使用 realpath('uploads/' . $newfilename);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 2014-02-04
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 2014-08-24
    • 1970-01-01
    相关资源
    最近更新 更多