PHP Create directory with permissions of another

你说的曾经没有我的故事 提交于 2020-01-11 14:15:15

问题


I would like to create a directory $one with the permissions of $another:

mkdir($one, fileperms($another));

It seems to me that the above could doesn't work correctly. Please help me find the problem.

I also tried:

mkdir($one);
chmod($one, fileperms($another));

edit to clarify

$one = "/tmp/somedir"
$another = "/tmp/anotherdir"

回答1:


fileperms($another) is not returning what you expect it to, there is much more information than you need.

From the docs -

on most platforms the return value will also include information on the type of file given as filename.

To account for that you'll have to get the substring you need from fileperms()

$one = "/tmp/somedir";
$another = "/tmp/anotherdir";
mkdir($one, substr(fileperms($another), -4));



回答2:


Try this code and avoid using this instead of chmod

      $none = 'folder name';
          if (!file_exists($none)) {
              mkdir($none, 0777);
          }



回答3:


Please try like following:

    $one = '/var/www/path';
    $another = 0777;
    mkdir($one);
    chmod($one, $another);


来源:https://stackoverflow.com/questions/29513997/php-create-directory-with-permissions-of-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!