我需要知道如何从我的数据库中的路径中删除 $imagenes...我无法成功(在数据库中已成功删除)...我已经放置了取消链接代码但在错误日志中显示图片的 id 但不是图片的名称...这是我的 PHP 代码:
---已编辑---
所以我不知道如何删除该id(idToDelete)中的$ imagenes ...我可以在之前或之后选择表吗?或者没有必要
这是桌子
- id_imagen (int PK)
- 图像(varchar 100)
- id_paciente (int FK)
- f_imagen (current_timestamp)
在personal.php中我有图像并通过ajax调用尝试删除它:
/*the styles of del button and wrapper */
<style type="text/css">
.del_wrapper{float:right;}
.content_wrapper {
max-width: 100%;
margin-right: auto;
margin-left: auto;
}
</style>
/*the ajax call */
<script type="text/javascript">
$(document).ready(function() {
$("body").on("click", "#gallery .del_button", function(e)
{
e.returnValue = false;
var clickedID = this.id.split('-');
var DbNumberID = clickedID[1];
var myData = 'recordToDelete='+ DbNumberID;
jQuery.ajax({
type: "POST",
url: "delimage.php?ts=" + new Date().getTime(),
dataType:"text",
data:myData,
success:function(response){
$('#item_'+DbNumberID).fadeOut("slow");
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
});
</script>
/*the image gallery */
<div id="gallery">
<?
$sql = $conn->prepare("select * from IMAGENES where id_paciente = $_GET[id_paciente] order by id_imagen ASC");
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC)){
$id_imagen = $row['id_imagen'];
$imagenes = $row['imagenes'];
echo "<div class='del_wrapper' id='item_".$row['id_imagen']."'><a href='#' class='del_button' id='del-".$row['id_imagen']."'>";
echo "<img src='../images/icon_del.gif' border='0' />";
echo "</a>";
echo "<a href='../$imagenes' class='group4'>";
echo "<img src='../$imagenes' class='image_thumbnail' />";
echo "</a> </div>";
}
?></div>
和delimage.php中的代码与选择:
<?
include_once("config.php");
if(isset($_POST["recordToDelete"]) && strlen($_POST["recordToDelete"])>0 && is_numeric($_POST["recordToDelete"]))
{
$stmt=$conn->prepare("SELECT id_imagen,imagenes FROM IMAGENES where id_imagen = $_GET[id_imagen]");
$result = $conn->query($sql);
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$recordToDelete=$data['imagenes'];
unlink("../imagenes/$imagenes");
}
$idToDelete = filter_var($_POST["recordToDelete"],FILTER_SANITIZE_NUMBER_INT);
if($stmt=$conn->prepare("delete from IMAGENES WHERE id_imagen=$idToDelete"))
$stmt->bindParam("$idToDelete",$id_imagen,PDO::PARAM_INT);
$stmt->execute();
$dbh = null;
}
?>
ajax 调用有效,因为在提琴手中,我看到图像的 id 将在 delimage.php 中删除它,但只删除 db 中的路径,而不是 imagenes 文件夹内的图像