0

出于某种原因,我的 php 脚本不会删除多个图像,它只是删除缩略图图像,然后将第二个图像留在目录中。

if($_POST['pic_id']){

    $pic_id = $_POST['pic_id'];
    $pic_id = mysql_escape_String($pic_id);

    # Select photo details from database
    $query = mysql_query("SELECT * FROM gallery WHERE id='$pic_id'");
    $queryCount = mysql_num_rows($query);

    if($queryCount>0){

    #Get the fields
    while($row = mysql_fetch_array($query)){         
    $image= $row["image"];
    $thumbnail = $row["thumbnail"];

    }

    # Unlink thumb source
    //Delete the thumbnail photo from directory
    $pic1 = ("$image");
    if (file_exists($pic1)) {
    unlink($pic1);
    }
    # Unlink resize source
    //Delete the big photo from directory
    $pic2 = ("$thumbnail");
    if (file_exists($pic2)) {
    unlink($pic2);
    }


    # Delete the row from the database
    $sqlTable2 = mysql_query("DELETE FROM gallery WHERE id='$pic_id'"); 

    } else {

        exit();
    }

 }   

几天来一直在努力让它工作,任何想法都表示赞赏。

4

1 回答 1

0

您需要将删除代码包装在您的 while 循环中......

while($row = mysql_fetch_array($query)){         
   $image= $row["image"];
   $thumbnail = $row["thumbnail"];

   # Unlink thumb source
   //Delete the thumbnail photo from directory
   $pic1 = ("$image");
   if (file_exists($pic1)) {
      unlink($pic1);
   }

   # Unlink resize source
   //Delete the big photo from directory
   $pic2 = ("$thumbnail");
   if (file_exists($pic2)) {
      unlink($pic2);
   }
}
于 2012-04-16T00:21:50.333 回答