2012-04-16 3 views
0

から複数の画像を削除する私のPHPスクリプトは複数の画像を削除しないので、単にサムネイル画像を削除してから2番目の画像をディレクトリに残します。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すべて同じ、三つの変数は必要ありません –

+0

何あなたは '$ image'と' $ thumbnail'で持っていますか? – mamadrood

答えて

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

関連する問題