gpt4 book ai didi

php - 通过数据库和目录删除图像

转载 作者:太空宇宙 更新时间:2023-11-03 12:33:03 24 4
gpt4 key购买 nike

有人可以帮助我获取代码吗?我可以删除数据库中的图像,但不能删除目录中的图像。我尝试了很长时间,但似乎根本不起作用。有人可以帮我吗?这是我的代码:这是图像的代码

<?
//this is were images displayed
$query = "SELECT * FROM images WHERE category='home'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
?>
<a href="edithomephotos.php?delete=<?=$row['imageID']?>" onclick = "return confirm('Are you sure you want to delete?')"><img src="images/template/delete.png" id="AEDbutton"></a>


echo "<img border=\"0\" src=\"".$row['image']."\" width=\"200\" height=\"100\">";
echo "<br>"; }


?>

,?

include('global.php');

//this is were image were deleted

if($delete != "")



{

$query = "DELETE FROM images WHERE imageID='".$delete."'";
ExecuteQuery($query);

}

//but in here , it cannot delete image through directory
$query = "SELECT * FROM images WHERE imageID='".$delete."'";

$result = mysql_query($query);

while ($delete = mysql_fetch_array($result)) {
$image = $delete['image'];

$file= '/.directory/'.$image;

unlink($file);


}



?>

最佳答案

您已经删除了表中的图像条目,之后您尝试在数据库中获取相同的条目。所以,首先你可以从文件夹中删除图像,然后你可以在表中删除。

<?php
include('global.php');

if($delete != "") {
$query = "SELECT * FROM images WHERE imageID='".$delete."'";
$result = mysql_query($query);

while ($delete = mysql_fetch_array($result)) {
$image = $delete['image'];
$file= '/.directory/'.$image;
unlink($file);
}

$query = "DELETE FROM images WHERE imageID='".$delete."'";
ExecuteQuery($query);
}
?>

注意:确保你的路径 $file= '/.directory/'.$image; 是正确的,我认为它是从根目录引用的。

关于php - 通过数据库和目录删除图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14481807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com