In PHP, umask() reads or changes the default permission mask. The mask decides which permissions are removed from files and folders that your script creates.
A new file normally starts with permissions 0666 and a folder with 0777. PHP then removes the bits in the mask. With a mask of 0022, a new file ends up as 0644 and a folder as 0755.
Syntax
Call umask() with the values you need. Start with this line.
PHP
$old = umask(0022);
Call
What it does
umask()
Returns the current mask without changing it.
umask(0022)
Sets the mask to 0022 and returns the old mask.
umask(0077)
Makes new files private, so only the owner can read and write them.
The mask applies to the current process only. A mask is written in octal, so always start it with 0, for example 0022. On Windows the function exists but has no real effect on permissions.
Library declarations
PHP
umask(?int $mask = null): int
Parameters
Parameter
Description
mask
Optional. The new mask in octal. If it is left out or null, the current mask is returned and nothing is changed.
Return Value
Return Value
Description
int
Returns the old mask when a new one is set. Without an argument, it returns the current mask.