2012-07-10 89 views
0

我的上传/裁剪功能几乎是我想要的。除了我不得不刷新我的页面显示上传的图像..然后,当我删除图像使用删除按钮进一步下来我的代码,我得到以下2个错误显示在我的头。除非我刷新页面,否则上传表单不会再显示,那么以下错误消失,直到我再次删除上传的图像。getimagesize错误

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

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; 
} 
+2

_“没有这样的文件或目录”_ - 对我来说似乎很清楚。打印您要打开的文件的路径并查看出了什么问题。 – CodeCaster 2012-07-10 12:20:11

+0

这就是我的想法..我的路径是mysite/imgs/ 是否当图像从服务器上被删除它仍然在寻找这样的图像..因为保存的图像在$ _SESSION ['id']; mysite/imgs/pic“。$ id。”。jpg mysite/imgs/cropped“。$ id。”jpg“ – dave 2012-07-10 12:31:23

+0

因为它寻找getimagesize(imgs/pic7.jpg),但如果我刚删除它不会在那里......所以我该如何纠正这一点,不要删除并用新文件覆盖文件! – dave 2012-07-10 12:33:31

回答

2

调用,当然删除图像getimagesize($image)应该给你的错误。在调用getimagesize($image)file_exists($file_path)函数之前检查文件是否存在。

+0

好的。谢谢拉斐尔。 – dave 2012-07-10 12:34:11

+0

像这样 'if(file_exists($ large_image_location) ){ \t如果(file_exists($ thumb_image_location)){ \t \t $ thumb_photo_exists = “\"Thumbnail”; \t}否则{ \t \t $ thumb_photo_exists = “”; \t} \t $ large_photo_exists =“\"Large”; } else { \t $ large_photo_exists =“”; \t $ thumb_photo_exists =“”; }' – dave 2012-07-10 12:35:44

+0

是的。类似的东西。 – 2012-07-10 12:37:46