douniao8687 2012-04-13 21:32
浏览 38
已采纳

文件不会使用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. 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>';
}
?>
  • 写回答

1条回答 默认 最新

  • douxi4414 2012-04-13 21:35
    关注

    You can't just run mysql_query() and expect it to return that value doc_link. You also have to run mysqli_fetch_array() to fetch the row, then access that value via $row['doc_link']. $pathresult is a MySQL resource, not a (String) path to a file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?