我正在尝试使用取消链接从已删除的评论中删除图片,但它根本不起作用。数据库中的评论被删除,但实际图片没有。我究竟做错了什么?文件夹权限为 755,图片权限为 644。
if (loggedin()) {
$dblink = mysqli_connect($DBhostname, $DBusername, $DBpassword, $DBname);
if (!$dblink) {die("Connection error (".mysqli_connect_errno.") " . mysqli_connect_error());}
$commentid = mysqli_real_escape_string($dblink, $_GET['c']);
$qry = "SELECT * FROM comments WHERE id='$commentid' LIMIT 1";
$result = mysqli_query($dblink, $qry) or die(mysqli_error($dblink));
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$commenter = $row["commenter"];
$thereisimg = $row["thereisimg"];
$imgtype = $row["imgtype"];
// if logged in email = email of commenter
if ($_SESSION["logged-in"] == $commenter) {
// delete comment
$qry = "DELETE FROM comments WHERE id=$commentid";
$result = mysqli_query($dblink, $qry) or die(mysqli_error($dblink));
// if image, delete image
if ($thereisimg) {
// delete image
$imglink = "/imgs/commentpics/".$commentid.".".$imgtype;
echo $imglink;
unlink($imglink);
}
}
}
}