PHP umask() Function
In this chapter you will learn:
- Definition for PHP umask() Function
- Syntax for PHP umask() Function
- Parameter for
- Return for PHP umask() Function
- Example - changes the file permissions for files
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/*ja va 2 s . co m*/
$old = umask(0);
chmod("test.txt", 0755);
umask($old);
// Checking
if ($old != umask()) {
die('An error occurred while changing back the umask');
}
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP unlink() Function
- Syntax for PHP unlink() Function
- Parameter for PHP unlink() Function
- Return for PHP unlink() Function
- Example - Delete a file
Home » PHP Tutorial » PHP File Functions