How to use Unlink() function

前端 未结 5 1033
说谎
说谎 2021-01-01 22:46

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

5条回答
  •  情书的邮戳
    2021-01-01 23:36

    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';
    

提交回复
热议问题