getimagesize错误

时间:2012-07-10 12:18:38

标签: php image getimagesize

我的上传/裁剪功能几乎是我想要的。除了我不得不刷新我的页面以显示上传的图像..然后当我使用删除按钮删除我的代码后面的图像时,我得到了我的标题中显示的以下2个错误。除非我刷新页面,否则上传表单不再显示,然后以下错误从视图中消失,直到我再次删除上传的图像。

这是两个错误,然后geERGize函数的代码标记为粗体。

  Warning: getimagesize(imgs/pic7.jpg) [function.getimagesize]: failed to open stream: No such file or directory in ----- on line 48

    Warning: getimagesize(imgs/pic7.jpg) [function.getimagesize]: failed to open stream: No such file or directory in ------ 42

这是问题的区域,两个错误标记为粗体 -

$id=$_SESSION['id'];
$upload_dir = "imgs";               // The directory for the images to be saved in
$upload_path = $upload_dir."/";             // The path to where the image will be saved
$large_image_name = "pic".$id.".jpg";       // New name of the large image
$thumb_image_name = "cropped".$id.".jpg"; 
$max_file = "1148576";                      // Approx 1MB
$max_width = "500";                         // Max width allowed for the large image
$thumb_width = "100";                       // Width of thumbnail image
$thumb_height = "100";                      // Height of thumbnail image

//Image functions
//You do not need to alter these functions
function resizeImage($image,$width,$height,$scale) {
    $newImageWidth = ceil($width * $scale);
    $newImageHeight = ceil($height * $scale);
    $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
    $source = imagecreatefromjpeg($image);
    imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
    imagejpeg($newImage,$image,90);
    chmod($image, 0777);
    return $image;
}
//You do not need to alter these functions
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
    $newImageWidth = ceil($width * $scale);
    $newImageHeight = ceil($height * $scale);
    $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
    $source = imagecreatefromjpeg($image);
    imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
    imagejpeg($newImage,$thumb_image_name,90);
    chmod($thumb_image_name, 0777);
    return $thumb_image_name;
}
//You do not need to alter these functions
function getHeight($image) {
    **$sizes = getimagesize($image);**
    $height = $sizes[1];
    return $height;
}
//You do not need to alter these functions
function getWidth($image) {
    **$sizes = getimagesize($image);**
    $width = $sizes[0];
    return $width;
}

1 个答案:

答案 0 :(得分:2)

当然,在已删除的图片上调用getimagesize($image)会给您带来错误。在使用getimagesize($image)函数调用file_exists($file_path)之前检查文件是否存在。