PHP mkdir() permissions
15,114
Solution 1
You should try with the umask
$old = umask(0);
mkdir($path,0777);
umask($old);
Solution 2
You can try:
chmod ( string $filename , int $mode )
See if that can fix the permissions issue.
Author by
samach
Updated on June 10, 2022Comments
-
samach about 2 years
I have a Linux server with appache as the web server. In my PHP script I am making directories with
0777
mode. the code is pretty simple as follows:mkdir($path,0777)
when I run this script and go to my server file manager, the folder is there but the permission assigned to that folder is 0755. I can't figure out why this is happening!! when the folder is created the user column has apache in it but the permission is 0755.
-
samach over 12 yearsthanks! solved the problem...but still confused why was my script nt able to create 777 folder permission?
-
Shakti Singh over 12 years@Salmanmahmood: This is something should be understand in Linux cyberciti.biz/tips/… just a link for your reference
-
MetaEd over 12 yearsNormally, umask is 022, which means to ignore any group or other write permissions. So if the permissions requested are 0777, then the permissions granted are 0777 - 022 = 0755.
-
qwertynik over 2 yearsChanging umask is not the safest way to do this. The approach suggested by Kart Funai here stackoverflow.com/a/7878810/3153786 is safer