我试图使用PHP unlink()函数删除文件夹中的特定文档。该特定文件夹已分配给IIS用户完全权限。
代码:
$Path = './doc/stuffs/sample.docx';
if (unlink($Path)) {
echo "success";
} else {
echo "fail";
}它使返回失败。sample.docx确实驻留在该特定路径上。敬请指教。
发布于 2012-07-13 03:21:24
我发现了这个信息在函数unlink()的注释中
在Windows系统和Apache中,拒绝对文件的访问是取消文件链接的常见错误。若要删除文件,必须更改文件的所有者。举个例子:
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';发布于 2012-07-13 03:07:37
试试这个:
$Path = './doc/stuffs/sample.docx';
if (file_exists($Path)){
if (unlink($Path)) {
echo "success";
} else {
echo "fail";
}
} else {
echo "file does not exist";
}如果您得到的文件不存在,您有错误的路径。如果没有,则可能是权限问题。
发布于 2012-07-13 04:19:50
一旦您完成了权限问题,这应该可以工作。也试着
ini_set('display_errors', 'On'); 那会告诉你怎么回事
https://stackoverflow.com/questions/11463581
复制相似问题