[英]File wont delete using unlink
The file below is supposed to delete both a file stored in a folder and the database row relating to that file. 下面的文件应该删除存储在文件夹中的文件和与该文件相关的数据库行。 The database row deletion works fine, but I am unable to get the file deletion to work.
数据库行删除工作正常,但我无法删除文件。 The doc_link is a table column that stores the relative path of the image.
doc_link是一个表列,用于存储图像的相对路径。 Any help would be greatly appreciated.
任何帮助将不胜感激。
The Code 编码
$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>';
}
?>
You can't just run mysql_query()
and expect it to return that value doc_link
. 你不能只运行
mysql_query()
并期望它返回该值doc_link
。 You also have to run mysqli_fetch_array()
to fetch the row, then access that value via $row['doc_link']
. 您还必须运行
mysqli_fetch_array()
来获取行,然后通过$row['doc_link']
访问该值。 $pathresult
is a MySQL resource, not a (String) path to a file. $pathresult
是MySQL资源,而不是文件的(String)路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.