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.


Surely this belongs on serverfault?

Written by Ben Everard

@ILMV: No; this is regarding PHP.

Written by Will Vousden

@ILMV - it's a question about PHP's mkdir, so I don't think so.

Written by Dominic Rodger

Accepted Answer

Just tested on gentoo linux with PHP 5.2.12: They all have the same permissions.

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
Written by soulmerge
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki