1

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

1 回答 1

4

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

于 2012-04-13T21:35:41.010 回答