Connecting Tech Pros Worldwide Forums | Help | Site Map

permissions

Fire Juggler
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi Guys,
I currently have this code:
mkdir("/usr/local/psa/home/vhosts/x-tractband.co.uk/httpdocs/x-tract/photos/
".$tab, 0777);

wen the directory is created it only has the permissons 755, any ideas why
this is this case?
Thanks

--
Kathryn (Fire Juggler)
http://www.firejugglers.34sp.com
http://www.cornwalljugglers.co.uk



SOR
Guest
 
Posts: n/a
#2: Jul 17 '05

re: permissions


<comp.lang.php , Fire Juggler , firejuggler@firejugglers.34sp.com>
<daotqu$1ic$1@news8.svr.pol.co.uk>
<Sat, 9 Jul 2005 17:26:06 +0100>
[color=blue]
> Hi Guys,
> I currently have this code:
> mkdir("/usr/local/psa/home/vhosts/x-tractband.co.uk/httpdocs/x-tract/photos/
> ".$tab, 0777);
>
> wen the directory is created it only has the permissons 755, any ideas why
> this is this case?
>[/color]

I seem to recall somebody from 34sp saying its only the first 7 thats
important .

Try 0766
Bert Melis
Guest
 
Posts: n/a
#3: Jul 17 '05

re: permissions


Fire Juggler wrote:[color=blue]
> Hi Guys,
> I currently have this code:
> mkdir("/usr/local/psa/home/vhosts/x-tractband.co.uk/httpdocs/x-tract/photos/
> ".$tab, 0777);
>
> wen the directory is created it only has the permissons 755, any ideas why
> this is this case?
> Thanks
>[/color]
I thought it was a bug.

just chmod to 0777 after making the dir.

function makedir($dir,$mode=0777){
mkdir($dir,$permission);
return chmod($dir,$permission);
}
Bert Melis
Guest
 
Posts: n/a
#4: Jul 17 '05

re: permissions


Fire Juggler wrote:[color=blue]
> Hi Guys,
> I currently have this code:
> mkdir("/usr/local/psa/home/vhosts/x-tractband.co.uk/httpdocs/x-tract/photos/
> ".$tab, 0777);
>
> wen the directory is created it only has the permissons 755, any ideas why
> this is this case?
> Thanks
>[/color]
At the PHP documentation you'll find this:

You might notice that when you create a new directory using this code:

mkdir($dir, 0777);

The created folder actually has permissions of 0755, instead of the
specified
0777. Why is this you ask? Because of umask(): http://www.php.net/umask

The default value of umask, at least on my setup, is 18. Which is 22
octal, or
0022. This means that when you use mkdir() to CHMOD the created folder
to 0777,
PHP takes 0777 and substracts the current value of umask, in our case
0022, so
the result is 0755 - which is not what you wanted, probably.

The "fix" for this is simple, include this line:

$old_umask = umask(0);

Right before creating a folder with mkdir() to have the actual value you
put be
used as the CHMOD. If you would like to return umask to its original
value when
you're done, use this:

umask($old_umask);
Closed Thread