php create new dir with 777 permission. How?

Js Lim picture Js Lim · Dec 10, 2011 · Viewed 7.9k times · Source

In my code

$path = 'images/product/'.$pid;
if( ! file_exists($path)) {
    mkdir($path, 0777);
}
...
...

but when I type

ls -l

in terminal

drwxr-xr-x 2 www-data www-data 4.0K 2011-12-10 19:28 1/

This is the permission that I get, but is not I want.

I want to allow web user to upload the project based on the product ID (directory) that created during runtime.

How can I do so?

Answer

rjv picture rjv · Jan 6, 2012

For creating directories with 777 permissions,or any permissions

$path = 'images/product/'.$pid;
if( ! file_exists($path)) {
    $mask=umask(0);
    mkdir($path, 0777);
    umask($mask);
}

...