php 不会删除 775 目录 chmod

发布于 2024-09-17 20:22:18 字数 308 浏览 4 评论 0原文

好的帮助我理解这一点。

我的 Linux 系统中有 2 个用户,它们都是“web-users”组的一部分。

一种是网络服务器和 php-cgi 使用的 www-data 一个是我的 ftp 用户,

当我通过 ftp 上传文件时,目录设置为 775,文件设置为 664,当我在服务器上运行脚本(与 ftp 用户相同的组)以删除该目录和其中的文件时: unlink对于文件工作正常,但命令 rmdir 不起作用返回权限被拒绝!?是的,目录被清空后被删除。

为什么775意味着该组的用户可以删除它,就像文件的664一样。

谢谢!

OK help me understand this.

I have 2 users in my linux system that are BOTH part of "web-users" group.

one is www-data used by the webserver and php-cgi
one is my ftp-user

when I upload files via ftp they are set to 775 for dirs and 664 for files, when I run a script on the server (so same group like the ftp user) to delete that directory and files inside: unlink for files works ok but the command rmdir doesnt work returning permission denied!? And yes the directory is deleted after is emptied.

why is that 775 means that the group's user can delete it just like 664 for files.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别理我 2024-09-24 20:22:18

您可以检查包含您尝试删除的目录的父级权限

本周早些时候,我删除了一些脚本生成的目录,即使将它们的权限设置为 777,我仍然收到“权限被拒绝”的消息,直到我授予自己对该目录的 Write 访问权限。 目录。

You might check the permissions of the parent that contains the directory you're trying to delete.

I was deleting some script-generated directories earlier this week and even with their permissions set to 777, I was still getting "permission denied" until I gave myself Write access to the parent directory.

浅忆 2024-09-24 20:22:18

我之前遇到过同样的问题,我的代码如下所示:

function recurse_delete_dir($dir) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file != '.' && $file != '..') {
                 $child_file = $dir . $file;
                 if (is_dir($child_file)) {
                     recurse_delete_dir($child_file);
                 }
                 else {
                     unlink($child_file);
                 }
            }
        }
        rmdir($dir);
    }
}

我自己认为这是权限问题,但事实证明我只需要在 rmdir-ing 之前调用 linedir 。所以:

closedir($dh);
rmdir($dir);

也许你的问题和我的类似?

I encountered the same problem before and my code looked like below:

function recurse_delete_dir($dir) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file != '.' && $file != '..') {
                 $child_file = $dir . $file;
                 if (is_dir($child_file)) {
                     recurse_delete_dir($child_file);
                 }
                 else {
                     unlink($child_file);
                 }
            }
        }
        rmdir($dir);
    }
}

I myself thought that it was permission issue but it turned out that I just needed to call closedir before rmdir-ing. So:

closedir($dh);
rmdir($dir);

Maybe your problem is similar to mine?

愿与i 2024-09-24 20:22:18

您不能在包含文件的目录上使用 rmdir()。在使用 rmdir() 删除目录之前,该目录必须为空

You can't use rmdir() on a directory that contains files. The directory must be empty before you use rmdir() to delete it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文