note 11411 added to mkdir

From: Date: Tue, 20 Feb 2001 06:15:43 +0000
Subject: note 11411 added to mkdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-11290@lists.php.net to get a copy of this message
Dear fellow idiots: (if your not an idiot, please ignore this section) I sat here scratching my head over this one little command for well over 3 hours today. Here is what I came up with and I hope this helps someone... First off, "umask". Somehow umask is set to something, on my server, it is set to 22. What this means is, no matter what I try to set the chmod value to, it is going to be blocked at the point that umask is set at. So to understand better what I'm showing you, go to your console and type in "umask" and press enter, write this number down, then type in "umask 0" and enter to tell umask not to block values. Now a word about values using chmod in console: Take a file name or directory of your choice and type in "chmod 7 myfile.txt". Now view your files "ls -al" press enter. what you will see is the last 3 attributes set to "rwx". Well then naturally typing in "chmod 8 myfile.txt" should render the 4th digit set and the last three open but it doesn't. You see, it's base 8, there for instead of 8 you would type a 10, "chmod 10 myfile.txt" and yes the 4th is set to x and the rest off. also, "chmod 17 myfile.txt" would set the last 4 digits "xrwx" but 18 would not be correct, it would be 20 (base 8 you know) "chmod 20 myfile.txt" renders "w----". Well if that is not bad enough, you should have noticed that the values where based on position like 1st is 1 and 2nd is 2 and 3rd is 4 and 4th is 8 (console value is 10) 5th is 16 (console value of 20) 6th is 32 (40) 7th is 64 (100) and 8th is 128 (200) and 9th is 256 (400). Are you confused or starting to see the pattern here? In linux console, you type "chmod 777 myfile.txt" you have actually typed a decimal value of 511 or (256+128+64+32+16+8+4+2+1) or as the 777 implies (400+200+100+40+20+10+4+2+1). Do you see it yet? Gets better, using mkdir(), to set a value of chmod 777 as in console mode, you would type in mkdir("mydir",511). and if you only wanted the last values "rwx" set it would be mkdir("mydir",7) or set "x---" would be mkdir("mydir",8) and NOT mkdir("mydir",10). So what about umask? well if umask is set to 2 then mkdir("mydir",7) would end up producing the same results as mkdir("mydir",5) because the umask would block the "w" in "rwx" from getting set. What about umask 22? Well at the console it would be "umask 22" but under php it would be umask(18). If you have been following me so far, you would know that umask(18) is the same as umask(16+2) and would block the "w's" in "wxrwx", you would get instead "-xr-x" as your result... Now what does all of these attributes actually mean? I found that the last x set allows me to delete the file or directory, and unset stops me from deleting it... If someone can help here and add to my note, please contribute.. (ps. remember to re-set umask to the value you found it at on your server) Barry L. Salter of "Hosting Master Internet" 602-410-8738 24/7 http://HostingMaster.net (Personalized Wholesale Web Hosting) http://www.php.net/manual/en/function.mkdir.php

« previous php.notes (#11290) next »