note 33513 added to function.mkdir

From: Date: Sat, 28 Jun 2003 09:00:16 +0000
Subject: note 33513 added to function.mkdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-51131@lists.php.net to get a copy of this message
You might notice that when you create a new directory using this code: mkdir($dir, 0777); The created folder actually has permissions of 0755, instead of the specified 0777. Why is this you ask? Because of umask(): http://www.php.net/umask The default value of umask, at least on my setup, is 18. Which is 22 octal, or 0022. This means that when you use mkdir() to CHMOD the created folder to 0777, PHP takes 0777 and substracts the current value of umask, in our case 0022, so the result is 0755 - which is not what you wanted, probably. The "fix" for this is simple, include this line: $old_umask = umask(0); Right before creating a folder with mkdir() to have the actual value you put be used as the CHMOD. If you would like to return umask to its original value when you're done, use this: umask($old_umask); ---- Manual Page -- http://www.php.net/manual/en/function.mkdir.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33513 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33513&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33513&report=yes

« previous php.notes (#51131) next »