mkdir with problem in the permission of the created folder

Asked

Viewed 614 times

0

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

mkdir("../../UPLOADS/$albumName","0775", true);
mkdir("../../UPLOADS/$albumName/thumbs","0775", true);
  • 2

    Already tried to pass the way as whole and not as string? See on documentation. In fact, read about the third parameter. If you use as true do not need to call the function twice.

1 answer

2

When you use the function mkdir with the parameter $mode, you must pass this parameter as int.

When you pass like string, the PHP automatically tries to convert to int. During this conversion, the value is modified by passing from 0775 for 755.

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

Since Linux works with this octal value, you end up missing 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)

Therefore, the recommended (The correct in fact) is to pass as whole.

mkdir("/path/to/folder", 0775, true);
  • It creates with permission 01341 only 775

  • @Fernandosantana, you have to put the 0 in front. Correct is 0775

Browser other questions tagged

You are not signed in. Login or sign up in order to post.