RE: [PHP] umask() and chmod()

From: Date: Thu, 15 Apr 2004 15:32:49 +0000
Subject: RE: [PHP] umask() and chmod()
Groups: php.general 
Request: Send a blank email to php-general+get-183474@lists.php.net to get a copy of this message
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" ; > > and get > > The setting is 664 > > when umask returns 113. All is great, right? Well, no... I need to > convert that 664 octal value into an octal representation of > > 0664 > > to feed to chmod() -- and apparently I can't just > > $r = 0.$r ; That would be $r = '0'.$r; I'm not sure, however, that this is a totally foolproof way of doing it, as it would fail with any permission set (however unlikely) where the owner odgit was a zero -- perhaps you should be sprintf()-ing it? 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: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#183474) next »