需要帮助通过 PHP 设置新目录的 Chmod 权限
我正在使用 PHP 的 mkdir 函数,但在使用 $mode 参数时遇到一些困难。如果我不指定参数,我将获得 UNIX 755 作为新目录的默认权限设置。我想将权限设置为 UNIX 777,所以我这样做了,如下所示:
$mode = '0700';
mkdir($newdir, $mode);
当我这样做时,会创建一个文件夹,但我无法对其执行任何操作。事实上我什至无法删除它!我所能做的就是通过 FTP 重命名它...
然后我尝试设置 $mode = '0600';这将创建一个可用的文件夹,但权限设置为 UNIX 110。这怎么可能? UNIX 值不应该是 600 吗?我在这里错过了一些转换吗?谢谢。
I am using PHP's mkdir function and I am having some difficulty with the $mode parameters. If I don't specify a parameter, I get UNIX 755 as the default permission settings of the new directory. I would like to set the permission to be UNIX 777, so I did that as you see here:
$mode = '0700';
mkdir($newdir, $mode);
When I do this a folder is created, but I cannot do anything with it. In fact I cannot even delete it! All I can do is rename it via FTP...
I then tried setting $mode = '0600'; This makes a workable folder, but the permissions are set to UNIX 110. How is this possible? Shouldn't it be a UNIX value of 600? Is there some conversion that I am missing out here? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
模式应该是数字,而不是字符串。尝试使用
$mode = 0700;
来代替。The mode is supposed to be a number, not a string. Try
$mode = 0700;
instead.根据 php.net 手册 mkdir 函数有这样的描述:
$mode 这里是一个整数(不是字符串),它必须以“0”开头,因为它是基于 8 的(不是基于 10 的)。
更新:(来自 php.net)请注意,您可能希望将模式指定为八进制数,这意味着它应该有一个前导零。该模式也会根据当前的 umask 进行修改,您可以使用 umask() 进行更改。
According to php.net manual mkdir function have this description:
$mode here is an integer (not a string) and it must be started with "0" because it 8-based (not an 10-based).
Update: (from php.net) Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask().
如果您想将其设置为 0777,请尝试以下操作:
阅读有关 umask 的更多信息,因为目录权限是 umask 和您指定的内容的组合。
If you want to set it to be 0777, try this:
Read more on umask as the directory permissions are a combination of the umask and what you specify.