Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.