2012-04-16 62 views
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(); 
    } 

} 

一直試圖讓它工作,任何想法讚賞。

+2

$行[「形象」] == $圖像== $ PIC1都是一樣的,不需要三個變量 – 2012-04-16 00:20:11

+0

什麼你有'$ image'和'$ thumbnail'嗎? – mamadrood 2012-04-16 00:22:09

回答

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); 
    } 
} 
+0

謝謝Cilliosis它現在的作品 – Raphael1 2012-04-16 00:24:42