繁体   English   中英

文件不会使用unlink删除

[英]File wont delete using unlink

下面的文件应该删除存储在文件夹中的文件和与该文件相关的数据库行。 数据库行删除工作正常,但我无法删除文件。 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>';
}
?>

你不能只运行mysql_query()并期望它返回该值doc_link 您还必须运行mysqli_fetch_array()获取行,然后通过$row['doc_link']访问该值。 $pathresult是MySQL资源,而不是文件的(String)路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM