note 77988 added to function.fileperms

From: Date: Sun, 23 Sep 2007 00:49:22 +0000
Subject: note 77988 added to function.fileperms
Groups: php.notes 
Request: Send a blank email to php-notes+get-130699@lists.php.net to get a copy of this message
If you need a function to return perms in format like (rwx etc) You can you use this code: function GetFilePerms($file) { $perms = fileperms($file); if (($perms & 0xC000) == 0xC000) {$info = 's'; } // Socket elseif (($perms & 0xA000) == 0xA000) {$info = 'l'; } // Symbolic Link elseif (($perms & 0x8000) == 0x8000) {$info = '-'; } // Regular elseif (($perms & 0x6000) == 0x6000) {$info = 'b'; } // Block special elseif (($perms & 0x4000) == 0x4000) {$info = 'd'; } // Directory elseif (($perms & 0x2000) == 0x2000) {$info = 'c'; } // Character special elseif (($perms & 0x1000) == 0x1000) {$info = 'p'; } // FIFO pipe else {$info = '?';} // Unknown // Owner $info .= (($perms & 0x0100) ? 'r' : '-'); $info .= (($perms & 0x0080) ? 'w' : '-'); $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); // Group $info .= (($perms & 0x0020) ? 'r' : '-'); $info .= (($perms & 0x0010) ? 'w' : '-'); $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); // World $info .= (($perms & 0x0004) ? 'r' : '-'); $info .= (($perms & 0x0002) ? 'w' : '-'); $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); return $info; } //Usage mode: //echo GetFilePerms("path/to/your/file"); ---- Server IP: 69.147.83.197 Probable Submitter: 189.13.147.252 ---- Manual Page -- http://www.php.net/manual/en/function.fileperms.php Edit -- https://master.php.net/note/edit/77988 Del: integrated -- https://master.php.net/note/delete/77988/integrated Del: useless -- https://master.php.net/note/delete/77988/useless Del: bad code -- https://master.php.net/note/delete/77988/bad+code Del: spam -- https://master.php.net/note/delete/77988/spam Del: non-english -- https://master.php.net/note/delete/77988/non-english Del: in docs -- https://master.php.net/note/delete/77988/in+docs Del: other reasons-- https://master.php.net/note/delete/77988 Reject -- https://master.php.net/note/reject/77988 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130699) next »