4
I was creating folders dynamically by PHP, when I came across the following situation.
Occurred
Create a folder tmp
with permission 777
in /www
mkdir('/www/tmp', intval('0777',8), true);
Turns out he’s not allowed 777, but 755;
drwxrwxrwx 3 www-data www-data 4096 Jun 8 17:51 .
drwxrwxrwx 3 www-data www-data 4096 Jun 8 17:51 ..
drwxr-xr-x 2 www-data www-data 4096 Jun 8 17:51 tmp
Solution
I added the command chmod
to be executed shortly thereafter
mkdir('/www/tmp', intval('0777',8), true);
chmod('/www/tmp', intval('0777',8));
And so it was with the desired permission 777
.
drwxrwxrwx 3 www-data www-data 4096 Jun 8 17:51 .
drwxrwxrwx 3 www-data www-data 4096 Jun 8 17:51 ..
drwxrwxrwx 2 www-data www-data 4096 Jun 8 17:51 tmp
Doubt
- Are there any settings in PHP that limit the permission a command can give? Ex.:
mkdir
could only use 444. - This was some PHP error?
Addendum
PHP is based on Shell. In Shell if I do :
mkdir /www/tmp;
drwxrwxrwx 3 www-data www-data 4096 Jun 8 17:51 .
drwxrwxrwx 3 www-data www-data 4096 Jun 8 17:51 ..
drwxr-xr-x 2 www-data www-data 4096 Jun 8 17:51 tmp
chmod 0777 /www/tmp;
drwxrwxrwx 3 www-data www-data 4096 Jun 8 17:51 .
drwxrwxrwx 3 www-data www-data 4096 Jun 8 17:51 ..
drwxrwxrwx 2 www-data www-data 4096 Jun 8 17:51 tmp
In other words, PHP could only be performing mkdir
? ignoring the second parameter intval('0777',8)
?
Remove the third parameter defined as
true
and test again, only mkdir(). intval() also unnecessary. Put 0777 without quotation marks or leave empty because the default is 0777.– Daniel Omine
Third parameter is recursive, therefore permission is not relevant.
– Don't Panic
@Danielomine the 2nd parameter should be octal based, if I convert a
string
for octal or directly for an octal, would be the same thing. As for the 3rd parameter is to leave the sub-folders (future) with the same permission. Even so I tested as you commented without 3rd and directly0777
the result was the same. :/– Guilherme Lautert