dorpbn1027 2015-05-08 17:22
浏览 39
已采纳

成功后收到unlink()错误

this might be a really stupid question but I am getting the following error after the code has successfully deleted the file and I can not work out why, the code is very simple it gets the name and path of the file to be deleted from the database and then deletes it.

Code:

$getFiles = mysql_query("SELECT * FROM tempFiles WHERE pTID='$passedId'");
$numFiles = mysql_num_rows($getFiles);

for ($f=0;$f<$numFiles;$f++) {

    $fileName = mysql_result($getFiles,$f,"fileName");
    $deleteFile = "../../".$fileName;
    unlink($deleteFile);

}

Warning: unlink(../../files/projects/files/643115.jpg): No such file or directory

The script for deleting the file is in a scripts/php/thefile and the file is in files/projects/files/thefile, so the ../../ is definitely needed and not the issue as far as I can tell. I know that the file is being deleted successfully because it is no longer in the folder after I run the script so I have no idea what is causing the error.

Any ideas why I might be getting the error?

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • dongzhan8001 2015-05-08 17:46
    关注

    Possible causes to the error:

    • There are more than 1 record in the tempFiles table with the same fileName, so the first attempt removes it and the second causes the error.
    • The file didn't exists on the folder when you ran the script (as @AxelAmthor said on comment)

    To solve it, just add a verification (as @Sammitch said on comment):

    if (is_file($deleteFile)) {
        unlink($deleteFile);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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()实现黑框里写入与删除?