Question

The question itself it quite simple, but it's really driving me crazy... I've read many other questions on Stack, but no matter how I change the code, the problem keeps occurring...

Why does...

if(!is_dir($dir)){
    clearstatcache();
    $mask = umask(0);
    if(mkdir($dir, 6750)) chmod($dir, 6750);
    umask($mask);
}

... produces...

d--s-wxrwT 2 owner group 4096 Jan 27 20:22 dir/

... when $dir is the absolute path to the newly created dir/ ?

As you can see, even though I request a 6750 permissions set, I get a lovely, yet useless, 5136... (the user and group, however, are correct) Here's what I've done :

  • Clearing the stat cache.
  • Setting the PHP umask to 0 before creating, and restoring it right after.
  • Chmod the newly created folder on success, just to be sure.

And here's what I know :

  • The system's umask value is 0037, which isn't the difference between 6750 and 5136.
  • The user creating the folder (www-data) has the same umask, and owns the parent directory with write permissions.
  • I can log as www-data on a terminal, and execute chmod 6750 succesfully, getting proper results.

Any reason why it seems like PHP forgot how to calculate ? Some questions mentionned an additional Apache2 parameters messing around, yet I cannot figure out which one...

Was it helpful?

Solution

Wont it be simpler without chmod($dir, 6750)?

$old = umask(0); 
mkdir($path, 06750); 
umask($old);

And one more thing your mode value should start from 0. Read manual about mode possible values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top