★ wanayoo — archive 1999 http://uk.php.net/manual/ro/function.umask.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<touchunlink>
view the version of this page
Last updated: Fri, 16 Jul 2004

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.



add a note add a note User Contributed Notes
umask
trisk at earthling dot net
31-Jan-2005 05: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
19-Jun-2004 02:43
$old = umask(0);
chmod("/some/dir", 0755);
umask($old);
sam at totallydigital dot co dot nz
20-Sep-2002 05: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
28-May-2001 01:47
save yourself some trouble by using umask with 4 digits, vs just three
wptate at olemiss dot edu
29-Feb-2000 09: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 02: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: Fri, 16 Jul 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This mirror generously provided by: Kewlio.net Limited
Last updated: Sat Feb 12 17:21:01 2005 GMT