note 98437 added to function.fileperms

From: Date: Tue, 15 Jun 2010 19:22:28 +0000
Subject: note 98437 added to function.fileperms
Groups: php.notes 
Request: Send a blank email to php-notes+get-170153@lists.php.net to get a copy of this message
Here is a small function I made : http://pastebin.com/iKky8Vtu I was bored and I thought it could be useful. mixed mkperms( string $perms [, bool return_as_string = false [, string $filename ] ] ) Returns permissions given a string in literal format and a filename. If the file name is omitted, the permissions that the function will return are based on 000-permissions. If return_as_string is set to true, the result will be output as a 644 format string. Otherwise it will return a string converted to base-10 for chmod. Examples: <?php echo mkperms('u+r', true), "\n"; // 400 echo mkperms('u+rwx,g+rw,o+x', true), "\n"; // 761 touch('myfile.txt'); // Create a file with any permissions chmod('myfile.txt', mkperms('u=rwx,g=x,o=rw')); // myfile.txt is now at -rwx--xrw- // Make a file and give it full permissions touch('somefile.txt'); chmod('somefile.txt', 0777); echo mkperms('g-w,o-rw', true, 'somefile.txt'); // 751 echo mkperms('u=rwx,g-r,o=-', true, 'somefile.txt'); // 730 // This way you can apply permissions to files chmod('somefile.txt', mkperms('u=rwx,g-r,o=-', false, 'somefile.txt')); // somefile.txt is now at -rwx-wx--- ?> PS : sorry I had to put it on pastebin, or else it just made the note way too long. ---- Server IP: 89.31.146.176 Probable Submitter: 82.228.41.155 ---- Manual Page -- http://www.php.net/manual/en/function.fileperms.php Edit -- https://master.php.net/note/edit/98437 Del: integrated -- https://master.php.net/note/delete/98437/integrated Del: useless -- https://master.php.net/note/delete/98437/useless Del: bad code -- https://master.php.net/note/delete/98437/bad+code Del: spam -- https://master.php.net/note/delete/98437/spam Del: non-english -- https://master.php.net/note/delete/98437/non-english Del: in docs -- https://master.php.net/note/delete/98437/in+docs Del: other reasons-- https://master.php.net/note/delete/98437 Reject -- https://master.php.net/note/reject/98437 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170153) next »