7

using PHP 5.2.14, this is what happens

[user@VE213 public_html]$ php -r "mkdir('directory', 0777);"
[user@VE213 public_html]$ ls -lt
drwxrwxr-x  2 rankranger rankranger 4096 Dec  8 17:28 directory

[user@VE213 public_html]$ php -r "chmod('directory', 0777);"
[user@VE213 public_html]$ ls -lt
drwxrwxrwx  2 rankranger rankranger 4096 Dec  8 17:28 directory

Did not find any related bugs in the php bug list, any idea?

Rup
  • 33,765
  • 9
  • 83
  • 112
meow
  • 71
  • 1
  • 2

3 Answers3

19
$old = umask(0);
mkdir($dir,0777);
umask($old);

Read this, http://php.net/manual/en/function.mkdir.php

Additional, Check the top directory that you make new directory.

Example)

pwd /data/log

$dir="/data/log/query";
$old = umask(0); 
mkdir($dir,0777); 
umask($old); 

/data/log must 0777.

Fluffeh
  • 33,228
  • 16
  • 67
  • 80
Hyeonju Kim
  • 229
  • 2
  • 3
6

This is not a bug. See http://php.net/umask - you probably have an umask of 0002. The permission of what you create is yourmode & ~umask, so it takes the write-bit for everyone away from 0777.

etarion
  • 16,935
  • 4
  • 43
  • 66
5

Working as documented. mkdir respects umask, chmod doesn't.

cdhowie
  • 158,093
  • 24
  • 286
  • 300
Tyler Eaves
  • 12,879
  • 1
  • 32
  • 39