下面的文件应该删除存储在文件夹中的文件和与该文件相关的数据库行。数据库行删除工作正常,但我无法让文件删除工作。doc_link 是一个表列,存储图像的相对路径。任何帮助将不胜感激。
编码
$delete = $_POST['checkbox'];
foreach ($delete as $id => $val) {
//Get file path stored in table and delete file
$relpath="SELECT doc_link FROM documents WHERE id = '".$id."'";
$pathresult= mysqli_query($con, $relpath) or die("Invalid query");
unlink($pathresult);
//Deletes row from table
$query="DELETE FROM documents WHERE id = '".$id."'";
$result= mysqli_query($con, $query) or die("Invalid query");
}
//Show that the items have been successfully removed.//
if (mysqli_affected_rows($con) > 0) {
echo '<p>The selected items have been successfully deleted.</p>';
} else {
echo '<p>An error has occurred while processing your request</p>';
}
?>