php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #37027 mkdir($dir, 0777, true) does NOT chmod created directory
Submitted: 2006-04-09 20:20 UTC Modified: 2008-05-24 09:47 UTC
From: spambox at gery dot pl Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.1.2 OS: Apache, Unix
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: spambox at gery dot pl
New email:
PHP Version: OS:

 

 [2006-04-09 20:20 UTC] spambox at gery dot pl
Description:
------------
Directory files/tmp/ has 777 chmod. Script creates files/tmp/tpl-cache/ with 755 chmod!

I use recursive because $foo can be 'admin/asf.tpl' too - then there are 2 directory to create.

I have seen this bug on PHP Version 5.0.4. It wasn't reported here so probably newest version of PHP has this bug too.

PHP5 is installed as CGI or something similar.

Please help!

I see now this: http://bugs.php.net/bug.php?id=19757 But I can reed on php.net/umask that: "Avoid using this function in multithreaded webservers. It is better to change the file permissions with chmod() after creating the file. Using umask() can lead to unexpected behavior of concurrently running scripts and the webserver itself because they all use the same umask."

So.. maybe we can change something to easier using mkdir()?

Reproduce code:
---------------
define('ROOT', dirname(__FILE__).'/');

$foo = 'asf.tpl'; // sample data
$dir = dirname(ROOT.'files/tmp/tpl-cache/'.$foo.'.html');

if(!is_dir($dir) && !mkdir($dir, 0777, true))
{
	die('Can not create directory structure for cached files.');
}

Expected result:
----------------
Directory with 777 chmod.

Actual result:
--------------
Directory with 755 chmod.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-09 20:37 UTC] tony2001@php.net
Reclassified as docu problem.
mkdir(dir, mode) actualy sets permissions to (mode & ~umask & 0777).
So you have to use umask() to
1) unset the correct umask; 
2) create the directory with mode 0777;
3) reset umask to it's old value.

OR you can use chmod() to change the permissions.
See also `man 2 mkdir`.
 [2006-04-10 14:15 UTC] vrana@php.net
It is already documented: "The mode is also modified by the current umask, which you can change using umask()."
 [2008-05-24 09:47 UTC] spambox at gery dot pl
Email update (because of spam).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 07:01:32 2025 UTC