PHP umask() Function
The PHP umask() function changes permissions for files. It 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.
Syntax
umask(mask)
Parameters
mask |
Optional. Specify the new umask. Default is 0777. The parameter consists of four numbers:
|
Return Value
Returns current umask if the function is called without arguments, otherwise the old umask is returned.
Example: umask() example
Lets assume that we have a file called test.txt in the current directory. In the example below, the umask() function is used to change the permissions for this file.
<?php $old = umask(0); //changing access chmod("test.txt", 0755); umask($old); if ($old != umask()) { die('An error occurred while changing back the umask'); } else { echo "umask is changed back successfully."; } ?>
The output of the above code will be:
umask is changed back successfully.
❮ PHP Filesystem Reference