使用mkdir的权限将不起作用 [英] Permissions with mkdir won't work

查看:85
本文介绍了使用mkdir的权限将不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么我必须使用 chmod 来获取正确的权限.该文件创建成功,但是使用我在 mkdir 中指定的0755而不是0775.

I can't understand why I have to use chmod to get the correct permissions.. The file is created succesfully but with 0755 and not 0775 that I specify in mkdir .

( http://php.net/manual/en/function.mkdir.php)

我必须在 mkdir 之后执行 chmod 来设置正确的权限.

I have to do chmod after mkdir to set the correct permissions.

php.ini中的安全模式已关闭,并且该文件夹属于php的组和所有者(www-data)

Safe mode is off in php.ini and the folder belongs to php's group and owner (www-data)

这不起作用:

  if(!is_dir("/var/www/customers/$username/$project_name")) 
  {
    mkdir("/var/www/customers/$username/$project_name",0775);

  }

但是确实如此:

  if(!is_dir("/var/www/customers/$username/$project_name")) 
  {
    mkdir("/var/www/customers/$username/$project_name");
    chmod("/var/www/customers/$username/$project_name",0775);

  }

推荐答案

是的,这是因为umask ...

Yes, it's because of umask...

来自文档评论: http://php.net/manual/zh/function.mkdir.php

您可能会注意到,当您创建使用此代码的新目录:

You might notice that when you create a new directory using this code:

mkdir($ dir,0777);

mkdir($dir, 0777);

创建的文件夹实际上有权限为0755,而不是指定的0777.为什么问这个?由于umask(): http://php.net/manual/zh/function.umask.php

The created folder actually has permissions of 0755, instead of the specified 0777. Why is this you ask? Because of umask(): http://php.net/manual/en/function.umask.php

umask的默认值,至少在我的设置中,是18.八进制是22,或者0022.这意味着当您使用mkdir()来CHMOD创建的文件夹时,0777,PHP用0777减去umask的当前值,在我们的情况0022,因此结果是0755-那不是你想要的可能.

The default value of umask, at least on my setup, is 18. Which is 22 octal, or 0022. This means that when you use mkdir() to CHMOD the created folder to 0777, PHP takes 0777 and substracts the current value of umask, in our case 0022, so the result is 0755 - which is not what you wanted, probably.

此修复程序"很简单,包括这行:

The "fix" for this is simple, include this line:

$ old_umask = umask(0);

$old_umask = umask(0);

在创建具有以下内容的文件夹之前mkdir()具有您的实际值用作CHMOD.如果你愿意想要将umask恢复为原始状态完成后,请使用以下值:

Right before creating a folder with mkdir() to have the actual value you put be used as the CHMOD. If you would like to return umask to its original value when you're done, use this:

umask($ old_umask);

umask($old_umask);

这篇关于使用mkdir的权限将不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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