问题描述
我正在尝试通过以下命令使用PHP在服务器上创建目录:
I'm trying to create a directory on my server using PHP with the command:
mkdir("test", 0777);
但是它不提供全部权限,仅授予以下权限:
But it doesn't give full permissions, only these:
rwxr-xr-x
推荐答案
该模式已由您当前的umask
修改,本例中为022
.
The mode is modified by your current umask
, which is 022
in this case.
umask
的工作方式是减法.您获得对mkdir
的初始许可权,并减去umask
以获得 actual 许可权:
The way the umask
works is a subtractive one. You take the initial permission given to mkdir
and subtract the umask
to get the actual permission:
0777
- 0022
======
0755 = rwxr-xr-x.
如果您不希望发生这种情况,则需要将umask
临时设置为零,以使其无效.您可以使用以下代码段进行此操作:
If you don't want this to happen, you need to set your umask
temporarily to zero so it has no effect. You can do this with the following snippet:
$oldmask = umask(0);
mkdir("test", 0777);
umask($oldmask);
第一行将umask
更改为零,同时将前一个存储到$oldmask
中.第二行使用所需的权限和(现在不相关的)umask
创建目录.第三行将umask
恢复为原始状态.
The first line changes the umask
to zero while storing the previous one into $oldmask
. The second line makes the directory using the desired permissions and (now irrelevant) umask
. The third line restores the umask
to what it was originally.
See the PHP doco for umask and mkdir for more details.
这篇关于为什么PHP无法创建具有777权限的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!