Php 逐个上载两个图像时imagedestroy不工作

Php 逐个上载两个图像时imagedestroy不工作,php,mysql,Php,Mysql,当我使用resize_image函数逐个上载两个图像时,第二个图像上载在第一列。两个图像都是相同的2和第一个图像,第二个图像超过第一个图像。但有时它会正常工作。imagedestroy有什么问题吗 function resize_image($file, $w, $h, $crop=false) { list($width, $height) = getimagesize($file); $r = $width / $height; if ($crop) {

当我使用resize_image函数逐个上载两个图像时,第二个图像上载在第一列。两个图像都是相同的2和第一个图像,第二个图像超过第一个图像。但有时它会正常工作。imagedestroy有什么问题吗

 function resize_image($file, $w, $h, $crop=false) {
    list($width, $height) = getimagesize($file);
    $r = $width / $height;
    if ($crop) {
        if ($width > $height) {
            $width = ceil($width-($width*abs($r-$w/$h)));
        } else {
            $height = ceil($height-($height*abs($r-$w/$h)));
        }
        $newwidth = $w;
        $newheight = $h;
    } else {
        if ($w/$h > $r) {
            $newwidth = $h*$r;
            $newheight = $h;
        } else {
            $newheight = $w/$r;
            $newwidth = $w;
        }
    }
    
    //Get file extension
    $exploding = explode(".",$file);
    $ext = end($exploding);
    
    switch($ext){
        case "png":
            $src = imagecreatefrompng($file);
        break;
        case "jpeg":
        case "jpg":
            $src = imagecreatefromjpeg($file);
        break;
        case "gif":
            $src = imagecreatefromgif($file);
        break;
        default:
            $src = imagecreatefromjpeg($file);
        break;
    }
    
    $dst = imagecreatetruecolor($newwidth, $newheight);
           imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    $file_name=time().'.png';
    $stamp=imagecreatefrompng('stamp.png');
    imagecopy($dst,$stamp,round($newwidth/2),round($newheight/2),0,0,60,17);
        imagejpeg($dst,PRODUCT_IMAGE_SERVER_PATH.$file_name);

    
        imagedestroy($dst); 
        imagedestroy($stamp); 
        imagedestroy($src); 

        return $file_name;
        imagedestroy($file_name); 
        


  
}
文件上载页*******使用imagedestroy

 $image=$_FILES['img1']['tmp_name'];
 

 $file1 = resize_image($image, 250, 250);



    $update_sql="update posted_ads set  name='$name', price='$price', age='$age', location='$location', image='$file1',salername='$salername',phoneno='$phone',detail='$detail' where id='$id'";
                mysqli_query($con,$update_sql);

                $file1 = imagecreatetruecolor(100, 100);
                imagedestroy($file1); 
            
      }
if($_FILES['img2']['name']!='') {

    


 $image=$_FILES['img2']['tmp_name'];

 $file2 = resize_image($image, 250, 250);

     $update_sql="update posted_ads set  name='$name', price='$price', age='$age', location='$location',imageTwo='$file2',salername='$salername',phoneno='$phone',detail='$detail' where id='$id'";
        mysqli_query($con,$update_sql);
        $file2 = imagecreatetruecolor(100, 100);
        imagedestroy($file2); 
    }
有时它在上传图像时起作用