PHP umask() Function
Definition
The umask() function changes the file permissions for files.
This function sets PHP's umask to mask & 0777 and returns the old umask.
Calling umask() without any arguments returns the current umask.
Syntax
PHP umask() Function has the following syntax.
umask(mask)
Parameter
Parameter | Is required | Description |
---|---|---|
mask | Optional. | New permissions. Default is 0777 |
The mode parameter consists of four numbers:
- The first number is always zero
- The second number specifies permissions for the owner
- The third number specifies permissions for the owner's user group
- The fourth number specifies permissions for everybody else
Possible values (to set multiple permissions, add up the following numbers):
- 1 = execute permissions
- 2 = write permissions
- 4 = read permissions
Return
umask() without arguments simply returns the current umask otherwise the old umask is returned.
Example
<?php//from w ww . j a v a 2 s . c om
$old = umask(0);
chmod("test.txt", 0755);
umask($old);
// Checking
if ($old != umask()) {
die('An error occurred while changing back the umask');
}
?>