Jump to: navigation, search

Php umask

From w3cyberlearnings

Contents

PHP function umask

This function uses to removed file permission from the system default permission when create a file. The purpose of using umask function is to secure a file for other to access or modify.

Syntax umask

permission defines the permission. It's default value is 0777.

umask(permission)

Permission

  • 1 = execute permission
  • 2 = write permission
  • 4 = read permission

The permission consists of four digits,

  • first digit: always starts with a zero
  • second digit : defines permission for owner
  • third digit: defines permission for owner's group
  • fourth digit: defines permission for everyone else

Permission example

  • 0777 (rwxrwxrwx) is owner, owner's group, and everyone else can execute, write, and read
  • 0775 (rwxrwxr-x) is owner can execute and write
  • 0700 (rwx------) is for owner has permission to execute, read, and write

Note

Do not use umask function to set the file permission. Use chmod function.

Example 1

<?php 
umask(0755);
$h1 = fopen("file1.txt",'w');
echo umask();
?>

Output

0755 (-----w--w-) for file1.txt

493 

Example 2

<?php
 $mrk = umask(0);
 $h2 = fopen("file2.txt","w");
 chmod("file2.txt",0770);
 umask($mrk); 
          
 if($mrk != umask()) {
   die ("error occured");
 }
 else {      
   echo "matched";
 }
    
?> 

Output

-rwxrwx--- 1 sophal sophal 0 2012-06-07 23:02 file2.txt

matched

Related Links


basename-- chgrp-- chmod-- chown-- clearstatcache-- copy-- delete-- dirname-- disk_free_space-- disk_total_space-- diskfreespace-- fclose-- feof-- fflush-- fgetc-- fgetcsv-- fgets-- fgetss-- file_exists-- file_get_contents-- file_put_contents- file-- fileatime-- filectime-- filegroup-- fileinode-- filemtime-- fileowner-- fileperms-- filesize-- filetype-- flock-- fnmatch-- fopen-- fpassthru-- fputcsv-- fputs-- fread-- fscanf-- fseek-- fstat-- ftell-- ftruncate-- fwrite-- glob-- is_dir-- is_executable-- is_file-- is_link-- is_readable-- is_uploaded_file-- is_writable-- is_writeable-- lchgrp-- lchown-- link-- linkinfo-- lstat-- mkdir-- move_uploaded_file-- parse_ini_file-- parse_ini_string-- pathinfo-- pclose-- popen-- readfile-- readlink-- realpath_cache_get-- realpath_cache_size-- realpath-- rename-- rewind-- rmdir-- set_file_buffer-- stat-- symlink-- tempnam-- tmpfile-- touch-- umask-- unlink--

Navigation
Web
SQL
MISC
References