Jump to content

How to change permessions with umask?


eldan88

Recommended Posts

Hey,

 

I have created a directory named new using the mkdir function...

mkdir("new", 0777);

When I created the directory it set the permessions to be 765.. I belive it set used the default permessions 0022 to get that value.

 

My question is how can apply umask to change it back to 0777? Thank you!

Link to comment
https://forums.phpfreaks.com/topic/274502-how-to-change-permessions-with-umask/
Share on other sites

You mean it created it as 0755?

 

The umask will disable those bits: 0777 & ~(0022) = 0755.

$oldumask = umask(0);
mkdir("new", 0777);
umask($oldmask);

 

However I wouldn't change the umask at all. It's easy to forget to change it back.

mkdir("new");
chmod("new", 0777);

You mean it created it as 0755?

 

The umask will disable those bits: 0777 & ~(0022) = 0755.

$oldumask = umask(0);
mkdir("new", 0777);
umask($oldmask);

 

However I wouldn't change the umask at all. It's easy to forget to change it back.

mkdir("new");
chmod("new", 0777);

 

Thanks for your answer. I have another question..what does is the purpost of the 0 interger that goes after the perenthisis of the umask function

what does is the purpost of the 0 interger that goes after the perenthisis of the umask function

 

The umask function takes one argument, which is the new umask to use. By doing umask(0) you're passing in 0 as the new umask, which essentially disables it.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.