mkdir with problem in permission of created folder [closed]

0

When I create the folder, it creates, but does not create with the correct permission, preventing it from creating the next folder, the chmod in the created folder comes 411.

mkdir("../../UPLOADS/$albumName","0775", true);
mkdir("../../UPLOADS/$albumName/thumbs","0775", true);
    
asked by anonymous 12.01.2018 / 23:52

1 answer

2

When you use the mkdir function with the $mode parameter, you should pass this parameter to int .

When you pass string , PHP automatically tries to convert to int . During this conversion, the value is changed from 0775 to 755 .

This is because PHP, by default, does not work with Octal, unlike the Unix chmod command.

As Linux works with this value in octal, you end up going wrong with this conversion. Example:

Value in Octal

0777 (octal) == binário 0b 111 111 111    == permissões rwxrwxrwx   (== decimal 511)

Value and decimal

777 (decimal) == binário 0b 1 100 001 001 == permissões sr----x--x  (== octal 1411)

So the recommended (The correct one actually) is to pass as an integer.

mkdir("/path/to/folder", 0775, true);
    
12.01.2018 / 23:57