7

When using mkdir() with the recursive flag set to true do all the created directories get the specified chmod or just the last one? For example:

mkdir('/doesnotExist1/doesnotExist2/doesnotExist3/', 0755, true);

Will the newly created directories /doesnotExist1/ and /doesnotExist1/doesnotExist2/ also get the same chmod as /doesnotExist1/doesnotExist2/doesnotExist3/ = 0755?

If not, is there any way to force the above behavior?

I would test this myself, but I don't have access to a *nix box ATM.

4

2 回答 2

7

刚刚在 gentoo linux 上使用 PHP 5.2.12 进行了测试:它们都具有相同的权限。

soulmerge@shark-g:~$ php -a
Interactive shell

php > mkdir('asd/def/ghi', 0700, 1);
php > ^C
soulmerge@shark-g:~$ ls -hal asd
total 12K
drwx------  3 soulmerge soulmerge 4.0K 2010-01-12 10:32 .
drwxr-xr-x 79 soulmerge soulmerge 4.0K 2010-01-12 10:32 ..
drwx------  3 soulmerge soulmerge 4.0K 2010-01-12 10:32 def
于 2010-01-12T09:33:04.893 回答
4

负责 mkdir('localfilesystem', x, true) 的 C 函数是 main/streams/plain_wrapper.c 中的 php_plain_files_mkdir()。它需要php_mkdir(dir, mode TSRMLS_CC);它应该创建的“第一个”目录和VCWD_MKDIR(buf, (mode_t)mode))所有子目录。php_mkdir() 进行一些安全模式检查,然后还调用VCWD_MKDIR 所以是的,mode 参数用于 mkdir(p, x, true) 创建的所有目录。

于 2010-01-12T09:40:55.453 回答