| chmod - octal values |
|
chmod - octal values In php, you have to use chmod with octal values, you cannot write something like : chmod('myFile.txt','g+w'); // this is incorrect I propose here an easy manner to "build" this number. Remember, there is 4 digits, which correspond to something like "0, user, group, public": 0754 for example. Common mannerFoe each one, you define the right like that :
You want the user to have all the rights? : 4 + 2 + 1 = 7 you want the group to have read and write rights : 4 + 2 = 6 you want that the public cannot even read the file : 0 The result is then 0760 (Don't forget the 0 at the beginning!), you write in php : chmod('myfile.txt', 0760); Note that the mode is a number, not a string! If you want now things more tricky, see next part. Advanced mannerWe will now see how to define some more rights, with no limitations like the previous manner. We have to deal with a bit of conversion between binary numbers and decimal numbers. Say you want to convert this very tricky linux formatted rights for you file: "-wxr-x--x". I show you directly this beautiful table:
I hope that by looking at the table you understand how this work, it's a bit complicated to explain it with words... Nevertheless here are some details :
Finally we get the result 0351, corresponding to "-wxr-x--x". Hope it was not to difficult to understand, don't hesitate to leave a comment otherwise.
Powered by !JoomlaComment 3.23
3.23 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||