0

所以我试图上传到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 失败或 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());


 }
     }

}
4

1 回答 1

0

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

于 2016-08-11T10:14:28.637 回答