为什么PHP无法创建具有777权限的目录? [英] Why can't PHP create a directory with 777 permissions?

查看:187
本文介绍了为什么PHP无法创建具有777权限的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下命令使用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.

有关 umask

See the PHP doco for umask and mkdir for more details.

这篇关于为什么PHP无法创建具有777权限的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆