我在PHP中使用unlink()
函数时遇到问题。我使用了一个复选框来删除图像或上传的视频文件。
从数据库中成功删除多个图像或视频,但不使用qazxsw poi从本地文件夹中删除。
没有错误,但是当我选中所有复选框并按删除时,数据库中的所有文件都将被删除,但只有第一个文件被取消链接。
这是我的代码:
unlink()
尝试<?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>";
}
}
}
?>
并检查文件名的密钥名称在访问数组项时更改此行
print_r($row);
至
$fname=$row[FILE_NAME];
用$fname=$row['the actual name of the field'];
替换$Path="data/58f60f2e09f07_jay/videos/$fname";
并用$Path="data/58f60f2e09f07_jay/videos/".$fname;
取代$row[FILE_NAME]