dongmu1951 2012-08-24 22:08
浏览 59
已采纳

php文件是可写的但无法删除

I am using this function. is_file and is_writable return true, but when I true to unlink, it gives an error. This is on windows server.

if(is_file($fileToDelete)) {
  if(is_writable($fileToDelete)) {
    unlink($fileToDelete);
  }
}

The file is a PDF document, which I have open. I thought is_writable would return false in this case, but it doesn't.

So how can I tell if a file can be deleted or not?

Thank you

  • 写回答

3条回答 默认 最新

  • douxun7992 2012-08-24 22:17
    关注

    What about doing it the other way around? Just try to delete the file and check whether it is really gone?

    @unlink($fileToDelete);
    
    if(is_file($fileToDelete)) {
       // file was locked (or permissions error)
    }
    

    Not sure whether this is workable in your specific case though, but judging by the code in your question this should be what you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题