问题
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