特定文件名的 rmdir() 错误?没有权限
首先,让我们解决这些问题:
- 目录上没有打开的句柄。
- 目录中没有文件。
- 将权限
chmod
为 0777 并不能防止该错误。 - 目录名称正确。
现在,这是我的问题。尝试删除目录时 rmdir() 抛出此错误:
rmdir(098f6bcd4621d373cade4e832627b4f6) [function.rmdir]: 第 124 行的 path\to\administrate.php 中的权限被拒绝
098f6bcd4621d373cade4e832627b4f6 是目录的名称。
这是脚本的相关部分。
if(is_dir($userhash)) :
foreach (new DirectoryIterator($userhash) as $fileInfo) {
$fileName = $fileInfo->getFilename();
if($fileInfo->isDot()) continue;
if(!rename($userhash.'/'.$fileName , 'trashcan/'.$username.'/'.$fileName)) {
echo '<p class="error">Could not move '.$fileName.'</p>';
$err = 1;
}
}
else :
echo '<p class="error">Unable to delete files! error: 67</p>';
$err = 1;
endif;
//JUST TO BE SURE
chmod('./',0777);
chmod($userhash,0777);
// RMDIR ONCE THE DIR IS EMPTY.
if(rmdir($userhash))
echo '<p class="success">Deleted the user directory. The files are in the trash.</p>';
else {
echo '<p class="error">Could not remove the user directory. Error: 656</p>';
$err = 1;
}
更新
我在同一目录中手动创建了目录'jake'
。我做了 rmdir('jake');
并且效果很好。现在,我在同一目录中手动创建了一个目录 '098f6bcd4621d373cade4e832627b4f6'
。我做了 rmdir('098f6bcd4621d373cade4e832627b4f6');
并且出错了!
更新 2
这开始看起来像一些奇怪的 rmdir()
bug,尽管看起来不太可能。以下是我创建的目录名称,然后尝试使用 rmdir 删除它;
098f6bcd4621d373cade4e832627b4f6 | didn't work (quintuple checked)
098f6bcd4621d373cade4e832627b4f7 | worked
098f6bcd4621d373cade4e832627b4f | worked
098f6bcd4621d373cade4e832627b4f66 | worked
First, let's get these out of the way:
- There are no open handles on the directory.
- There are no files in the directory.
chmod
ing the permissions to 0777 does not prevent the error.- the directory name is correct.
Now then, here's my problem. rmdir()
is throwing this error when trying to delete the directory:
rmdir(098f6bcd4621d373cade4e832627b4f6) [function.rmdir]: Permission denied in path\to\administrate.php on line 124
098f6bcd4621d373cade4e832627b4f6 is the name of the directory.
Here is the relevant portion of the script.
if(is_dir($userhash)) :
foreach (new DirectoryIterator($userhash) as $fileInfo) {
$fileName = $fileInfo->getFilename();
if($fileInfo->isDot()) continue;
if(!rename($userhash.'/'.$fileName , 'trashcan/'.$username.'/'.$fileName)) {
echo '<p class="error">Could not move '.$fileName.'</p>';
$err = 1;
}
}
else :
echo '<p class="error">Unable to delete files! error: 67</p>';
$err = 1;
endif;
//JUST TO BE SURE
chmod('./',0777);
chmod($userhash,0777);
// RMDIR ONCE THE DIR IS EMPTY.
if(rmdir($userhash))
echo '<p class="success">Deleted the user directory. The files are in the trash.</p>';
else {
echo '<p class="error">Could not remove the user directory. Error: 656</p>';
$err = 1;
}
Update
I manually created the dir 'jake'
in the same directory. I did rmdir('jake');
and it worked great. Now, I manually created a dir '098f6bcd4621d373cade4e832627b4f6'
in the same directory. I did rmdir('098f6bcd4621d373cade4e832627b4f6');
and it errored!
Update 2
This is beginning to look like some weird rmdir()
bug, as unlikely as that seems. Here are directory names I've created and then tried to remove with rmdir
;
098f6bcd4621d373cade4e832627b4f6 | didn't work (quintuple checked)
098f6bcd4621d373cade4e832627b4f7 | worked
098f6bcd4621d373cade4e832627b4f | worked
098f6bcd4621d373cade4e832627b4f66 | worked
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了能够删除文件:
更新:
关于限制删除标志 - 来自
man chmod
:可以通过在mode的第一个八进制数字上加1来设置,例如:
UPDATE 2:
执行php的用户是否有chmod父目录的权限?
换句话说,您确定第一个 chmod 调用返回 true 吗?
In order to be able remove file:
UPDATE:
About restricted deletion flag - from
man chmod
:You may SET it by adding 1 to the first octal digit in mode, for example:
UPDATE 2:
Does user, under which php is executed, has permissions to chmod parent directory?
In other words, are you sure that first chmod call returns true?