On 15 April 2004 16:26, David T-G wrote:

> Hi, all --
> 
> When I move_uploaded_file() a file into place, I want to give it the
> correct permissions; by default they are 600 (rw-/---/--).  I already
> have the umask set correctly for any given situation in
> anticipation of
> creating directories, and that works for creating files from scratch,
> but chmod() needs a permissions setting rather than a umask.
> 
> The challenge is in representing this as octal.  With some
> mucking around
> I was able to print
> 
>   $u = decoct(umask()) ;
>   $m = 0777 ;
>   $r = decoct($m) - $u ;
>   print "The setting is $r\n" ;

I've just re-read this properly, and realised you want to feed the end value to 
chmod() -- so all the guff about octal representations is a complete red herring.  
What you want to feed to the 2nd parameter of chmod() is just:

    0777 ^ umask()

Within the computer, the value is just an integer, and that's what umask() provides 
and what chmod() expects for its 2nd argument -- so no conversions required.  Even 
0777 is an integer -- it's just a different way of representing 511 which is more 
understandable to us poor humans in that context.

Your original offering was, in fact, barking up the wrong tree -- what it was printing 
out, although it looked right, was the *decimal* value 664, which in octal would be 
01230 and really not what you want.

I guess what this boils down to is that integers are just integers when you manipulate 
them in your script -- octal, decimal, hex and any other representations are just 
convenient notations for making them more human readable.

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to