我在PHP中使用unlink()时遇到问题... 见代码:
JS:
$(".delete").on("click", function() {
var id = $(this).data("id");
$("#status").text("Deleted");
$.post("adminServer.php", { id: id }, function(data) {
data = JSON.parse(data);
alert(data);
});
});
PHP:
$id = $_POST['id'];
$sql = "SELECT * FROM `upload_img` WHERE `id` = '$id'";
$result = mysqli_query($db, $sql);
$row = mysqli_fetch_assoc($result);
$target = "/uploads/".$row['image'];
chmod($target, 0777);
unlink($target);
$sql = "DELETE FROM `upload_img` WHERE `id` = '$id'";
$result = mysqli_query($db, $sql);
if ($result == true) {
$check = "Sucessfully deleted";
} else {
$check = "Error while deleting";
}
echo json_encode($check);
它没有告诉我错误和图像没有删除...
我不知道为什么这不起作用...请帮忙!
谢谢!