我正在尝试使用 PHP unlink()
函数删除文件夹中的特定文档。该特定文件夹已被分配给 IIS 用户的完全权限。
代码:
$Path = './doc/stuffs/sample.docx';
if (unlink($Path)) {
echo "success";
} else {
echo "fail";
}
它保持返回失败。 sample.docx 确实驻留在该特定路径上。请指教。
最佳答案
我找到了这个信息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);
所以尝试这样的事情:
$path = './doc/stuffs/sample.docx';
chown($path, 666);
if (unlink($path)) {
echo 'success';
} else {
echo 'fail';
}
编辑 1
尝试在路径中使用它:
$path = '.'
. DIRECTORY_SEPARATOR . 'doc'
. DIRECTORY_SEPARATOR . 'stuffs'
. DIRECTORY_SEPARATOR . 'sample.docx';
关于php - 如何使用 Unlink() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11463581/