我的上傳/裁剪功能幾乎是我想要的。除了我不得不刷新我的頁面顯示上傳的圖像..然後,當我刪除圖像使用刪除按鈕進一步下來我的代碼,我得到以下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;
}
_「沒有這樣的文件或目錄」_ - 對我來說似乎很清楚。打印您要打開的文件的路徑並查看出了什麼問題。 – CodeCaster 2012-07-10 12:20:11
這就是我的想法..我的路徑是mysite/imgs/ 是否當圖像從服務器上被刪除它仍然在尋找這樣的圖像..因爲保存的圖像在$ _SESSION ['id']; mysite/imgs/pic「。$ id。」。jpg mysite/imgs/cropped「。$ id。」jpg「 – dave 2012-07-10 12:31:23
因爲它尋找getimagesize(imgs/pic7.jpg),但如果我剛刪除它不會在那裏......所以我該如何糾正這一點,不要刪除並用新文件覆蓋文件! – dave 2012-07-10 12:33:31