Search code examples
phppermissionsmkdir

mkdir ignore mode, but use recursive parameter


PHP's mkdir function has the following signature:

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

I would like to call this function specifying the $pathname and $recursive set to true, but I wouldn't like to specify the $mode parameter. We control permissions on new files/directories on the server level and as such don't wish to specify them in my code.

So what should I pass as $mode so that it is effectively ignored and no chmod-ing takes place? I haven't found a way.

Maybe the only solution is to write a custom mkdir function that will break the path and create directories one by one?


Solution

  • Why don't you set the mode to the default value 0777.