dongxibeng5324 2012-07-13 03:03
浏览 72
已采纳

如何使用Unlink()函数

I'm trying to use PHP unlink() function to delete away the specific document in the folder. That particular folder has already been assigned to full rights to the IIS user.

Code:

$Path = './doc/stuffs/sample.docx';
if (unlink($Path)) {    
    echo "success";
} else {
    echo "fail";    
}

It keep return fail. The sample.docx does reside on that particular path. Kindly advise.

  • 写回答

5条回答 默认 最新

  • drdawt9210 2012-07-13 03:21
    关注

    I found this information in the comments of the function unlink()

    Under Windows System and Apache, denied access to file is an usual error to unlink file. To delete file you must to change the file's owner. An example:

    chown($tempDirectory . '/' . $fileName, 666); //Insert an Invalid UserId to set to Nobody Owern; 666 is my standard for "Nobody" 
    unlink($tempDirectory . '/' . $fileName); 
    

    So try something like this:

    $path = './doc/stuffs/sample.docx';
    
    chown($path, 666);
    
    if (unlink($path)) {
        echo 'success';
    } else {
        echo 'fail';
    }
    

    EDIT 1

    Try to use this in the path:

    $path = '.'
             . DIRECTORY_SEPARATOR . 'doc'
             . DIRECTORY_SEPARATOR . 'stuffs'
             . DIRECTORY_SEPARATOR . 'sample.docx';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度