質問

I have a directory that is writable.If i make another directory inside it using

mkdir("test", 0777);

Does this make test directory writable ?

if i use only

mkdir("test");

does it inherit the writable property from its parent dir?

If not is there a way to make it inherit. So that i do not have to individually make it writable?

役に立ちましたか?

解決

Your both supposed options are not true. Result permissions will not be neither exact 777 nor "inherited" from parent directory.

To understand what will happen, you need to understand two points:

  • What is umask. In *nix systems it's a special mask that is applied to newly created file system elements (directories or files. Well, actually, directory is a file too, but that's out of issue). You can work with it in PHP via umask()
  • For mkdir() second parameter is not just "exact permissions". umask will modify it. So end result may (and, best chances are - will be) differ from 777.

Also there's important to realize - that Windows permissions systems is different from *nix - you can not rely on described above when working under Win systems.

他のヒント

No, directories nor files do not inherit attributes from parent element. But test will be world writable because you explicitly set it so with 0777. We have 3 octal digits these digits represent the rights of, in order, owner, group and world to the resource. since 8 is the 3rd power of 2 we can represent 3 states with each octal digit (since 4+2+1=7) depending on which values are set (this is a bitmask i.e. based on powers of 2, handy to manipulate with bitwise operations)

1 = executable
2 = writable
4 = readable

The second parameter of mkdir is the access mask for the new directory.

mkdir( 'test', 0777 );

Would create the directory test at your current location (getcwd()) and make it writeable for everyone.

Access rights are not inherited, they are set separately for each file and directory

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top