0

私のアップロード/クロップ機能は、ほぼ希望どおりに機能しています。アップロードした画像を表示するためにページを更新する必要があることを除いて..そして、コードの下にある削除ボタンを使用して画像を削除すると、ヘッダーに次の2つのエラーが表示されます。また、ページを更新しない限り、アップロード フォームは再び表示されず、アップロードされた画像を再度削除するまで、次のエラーが表示されなくなります。

2 つのエラーと、太字でマークされた 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

これは、太字でマークされた 2 つのエラーがある問題の領域です -

$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;
}
4

1 に答える 1

2

getimagesize($image)もちろん、削除された画像を呼び出すと、エラーが発生するはずです。getimagesize($image)関数で呼び出す前に、ファイルが存在するかどうかを確認してくださいfile_exists($file_path)

于 2012-07-10T12:32:01.407 に答える