• PHP Video Tutorials

PHP - Function umask()



The umask() function can change file permissions for files. This function can set PHP's umask to mask & 0777 and return the old umask. However, if we call the umask() function without any arguments, and return the current umask.

Syntax

int umask ([ int $mask ] )

This function can set PHP's umask to mask & 0777 and return old umask. When PHP is being used as a server module, the umask is restored when each request is finished.

The umask() function without arguments can simply return the current mask. Otherwise, an old umask is returned.

Example

<?php
   $old = umask(0);
   chmod("PhpProject/php/sample.txt", 0755);
   umask($old);

   //  Checking
   if($old != umask()) {
      echo "An error occurred while changing back the umask";
   }
?>
php_function_reference.htm
Advertisements