search for in the  
<touchunlink>
Last updated: Thu, 19 May 2005

umask

(PHP 3, PHP 4, PHP 5)

umask -- Changes the current umask

Description

int umask ( [int mask] )

umask() sets PHP's umask to mask & 0777 and returns the old umask. When PHP is being used as a server module, the umask is restored when each request is finished.

umask() without arguments simply returns the current umask.



User Contributed Notes
umask
rwelti at yahoo dot com
20-Apr-2005 05:35
trisk above talks about leading 0's and others talk about 4 digit umasks.

confused me for some time.

to get an octal value try a leading o  (OH) not 0 (zero)

so umask(o666);  for example
andi<at>splitbrain.org
03-Mar-2005 04:03
To play around with umasks and permissions use this little fragment:

<?
$umask
= 0012;
$perm  = 0777;
printf("umask: %04o perm: %04o result: %04o\n",
      
$umask,$perm,$perm & (0777 - $umask));
?>
trisk at earthling dot net
31-Jan-2005 11:25
I thought I would clarify the numbering scheme used here, as it confused me at first.

On the UNIX console, the command:

umask "blah"

In this instance, the umask command forces "blah" to be an octal number, regardless of how many digits you use and regardless of any leading zeroes.  In PHP, umask() does not default to octal as the console command does, it uses whatever numeric format you specify.

For example:

umask(213);

This uses the decimal integer 213 and not the octal number 213 as you would expect when using the console command.  In this case, it would set the umask to the octal number "325".

To enter the number as octal, just add one or more zeroes to the left of the number:

umask(0213);
umask(07);
umask(0044);

etc.
notepad at codewalkers dot com
18-Jun-2004 08:43
$old = umask(0);
chmod("/some/dir", 0755);
umask($old);
sam at totallydigital dot co dot nz
19-Sep-2002 11:04
The first comment perhaps didn't quite make clear what's on with your umask and the permissions.

The permission passed to a command is first bitwise ANDed with the _INVERSE_ of the current umask, then applied to the file.

For example, umask = 0011 and permission = 0775
The inverse of 0011 = 0766

0775 AND 0766
= 111.111.101 AND 111.110.110
= 111.110.100
= 0764
voudras at swiftslayer dot org
27-May-2001 07:47
save yourself some trouble by using umask with 4 digits, vs just three
wptate at olemiss dot edu
29-Feb-2000 03:19
The -S option will print the symbolic values of umask, while changing the umask to the new setting. 
(i.e. umask -S 007 will print 'u=rwx,g=rwx,o=')
rlynch at ignitionstate dot com
11-Feb-2000 08:41
umask affects permissions when files and directories are created.<BR>
umask is short for "Un-Mask".<BR>
So umask is "and"ed with the permissions of mkdir, fopen, etc.<BR>
In a sense, the umask setting is "subtracted" from the permissions given to mkdir.<BR>
Example:<BR>
<PRE>
umask(011);
mkdir('foo', 0777);
</PRE>
will actually make a directory with permissions 0766.

<touchunlink>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT