Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mkdir 0777 fail chmod 0777 works

Tags:

php

chmod

mkdir

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?

like image 888
meow Avatar asked Dec 08 '10 17:12

meow


1 Answers

$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.

like image 125
Hyeonju Kim Avatar answered Oct 06 '22 20:10

Hyeonju Kim