1
好的,底線是。我的網站上有一個圖片庫。我可以上傳和檢索圖像到我的Mysqli數據庫。多個圖像放置在佔位符div中,其中顯示圖像周圍的一個小框以及圖像的名稱。每個圖像都有一個與PHP取消鏈接一起使用的刪除功能。但是,每當我刪除圖像,圖像的框和名稱仍然出現。php unlink div或div div in變量
有沒有辦法不只是取消鏈接圖像,而是整個div所以佔位符將完全刪除?或者,有沒有辦法將div放在變量中,因爲我知道如何解除包含多個文件的變量的鏈接。這裏是我的代碼
該div被稱爲「媒體」。
<ul class="media-list">
<?php
include "config.php"; //database connection
$res = $mysqli->query("SELECT * FROM upload_data");
while ($row = $res->fetch_assoc()):
?>
<div class="media">
<a class="media-left" href="#">
<!-- <img src="upload/<?php echo $row['file_name'] ?>" alt="<?php echo $row['file_name'] ?>"> -->
</a>
<div class="img"><?php if (isset($_SESSION['email']))
{
echo '<a href="delete.php?id=&nm=<?php echo $row[\'file_name\'] ?>">Delete</a>';} ?>
<a target="_blank" href="javascript:popImage('upload/<?php echo $row['file_name'] ?>','<?php echo $row['file_name'] ?>')">
<img width="300" height="200" src="upload/<?php echo $row['file_name'] ?>" alt="<?php echo $row['file_name'] ?>">
</a>
</div>
</div>
<?php
endwhile;
?>
這裏也取消鏈接代碼,如果你想知道:
<?php
include "config.php";
if(isset($_GET['id'])):
$hap = unlink('upload/'.$_GET['nm']);
if($hap){
$stmt = $mysqli->prepare("DELETE FROM upload_data WHERE id_upload=?");
$stmt->bind_param('s', $id);
$id = $_GET['id'];
if($stmt->execute()):
echo "<script>location.href='gallery.php'</script>";
else:
echo "<script>alert('".$stmt->error."')</script>";
endif;
} else{
echo "<script>alert('No Delete File From Harddisk')</script>";
echo "<script>location.href='gallery.php'</script>";
}
endif;
?>