未捕获的异常:无法打开文件

时间:2016-08-11 09:51:05

标签: php uploadcare

所以我试图上传到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']);

// IF MIME FAILES或GETIMAGESIZE为NULL(表示没有图像)         if(!getimagesize($ _ FILES [' uploadimage'] [' tmp_name'])&&!in_array($ _ FILES [' uploadimage'] [&# 39; tmp_name的值'],$ MIME)){        $ errors [] ='请选择图片&#39 ;;        未设置($ _ 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());


 }
     }

}

1 个答案:

答案 0 :(得分:0)

我修好了。我不得不使用realpath('上传/'。$ newfilename);