我在PHP中使用unlink()
函数时出现问题。我使用了一个复选框来删除图像或上传的视频文件。使用复选框删除多个图像不会从文件夹中取消链接文件
从数据库中成功删除多个图像或视频,但使用unlink()
从本地文件夹中删除。
没有错误,但是当我选择所有复选框并按下delete时,数据库中的所有文件都将被删除,但只有第一个文件未被链接。
这是我的代码:
<?php // for delete checked video php script
include('config.php');
if(isset($_POST['delete'])) {
$checkedCandidates = 0;
$id = implode(",", $_POST['deletecb']);
$checkedCandidates = count($id);
if ($checkedCandidates < 1) {
echo "<div id=\"errormsg\"> You need to check at least one video for delete. </div>";
echo "<script>setTimeout(\"location.href = 'video_upload.php';\",3000);</script>";
} else {
$result=mysqli_query($connection,"SELECT * FROM video_gallery where id_vid IN($id) and users_name='$login_session'");
while ($row=mysqli_fetch_assoc($result)) {
$fname=$row[FILE_NAME];
$Path="data/58f60f2e09f07_jay/videos/$fname";
if (file_exists($Path)){
if (unlink($Path)) {
echo "success";
} else {
echo "fail";
}
} else {
echo "file does not exist";
}
}
$query1=mysqli_query($connection,"delete from video_gallery where id_vid IN($id) and users_name='$login_session'");
if($query1) {
echo "<div id=\"successmsg\"> delete successfully </div>";
} else {
echo "<div id=\"errormsg\"> failed operation!!</div>";
}
}
}
?>
更换
$row[FILE_NAME]
感谢它完成了...字段名称是正确的,但我缺少“”像这样$ FNAME = $行[文件名]。并使用''$ fname = $ row ['FILE_NAME']解决; – pranay不用客气 – Exprator