siannone
siannone

Reputation: 6763

Wrong permissions set on newly created directory

This is the code that creates the "cache" folder with the wrong permissions:

mkdir($saveFolder, 02775);

When I inspect the folder permissions, using ls -la, I receive:

drwxr-sr-x

But instead I'm expecting:

drwxrwsr-x

Upvotes: 7

Views: 981

Answers (2)

You Old Fool
You Old Fool

Reputation: 22960

Your current umask also affects the mode so depending on your umask settings, the mode of the created directory may not match the octal specified in your function call. http://php.net/manual/en/function.mkdir.php:

The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page. Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask().

Try setting umask(0) and the argument supplied to mkdir() should work as expected.

More discussion here: https://bugs.php.net/bug.php?id=65796

Upvotes: 2

siannone
siannone

Reputation: 6763

For some obscure reasons (at least for me) changing the code to

mkdir($saveFolder);
chmod($saveFolder, 02775);

solved the issue.

Now I get the right permissions set on the folder:

drwxrwsr-x

Upvotes: 7

Related Questions