note 36883 added to function.fileperms
| From: | zilinex at linuxmail dot com | Date: | Sun, 26 Oct 2003 08:48:08 +0000 |
| Subject: | note 36883 added to function.fileperms | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-59297@lists.php.net to get a copy of this message | ||
here is the correct translation for the fileperms like the ls shows is with the option -l :
function TranslatePerm( $in_Perms ) {
$sP;
if(($in_Perms & 0xC000) == 0xC000) // Socket
$sP = 's';
elseif(($in_Perms & 0xA000) == 0xA000) // Symbolic Link
$sP = 'l';
elseif(($in_Perms & 0x8000) == 0x8000) // Regular
$sP = '−';
elseif(($in_Perms & 0x6000) == 0x6000) // Block special
$sP = 'b';
elseif(($in_Perms & 0x4000) == 0x4000) // Directory
$sP = 'd';
elseif(($in_Perms & 0x2000) == 0x2000) // Character special
$sP = 'c';
elseif(($in_Perms & 0x1000) == 0x1000) // FIFO pipe
$sP = 'p';
else // UNKNOWN
$sP = 'u';
// owner
$sP .= (($in_Perms & 0x0100) ? 'r' : '−') .
(($in_Perms & 0x0080) ? 'w' : '−') .
(($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x' ) :
(($in_Perms & 0x0800) ? 'S' :
'−'));
// group
$sP .= (($in_Perms & 0x0020) ? 'r' : '−') .
(($in_Perms & 0x0010) ? 'w' : '−') .
(($in_Perms & 0x0008) ? (($in_Perms & 0x0400) ? 's' : 'x' ) :
(($in_Perms & 0x0400) ? 'S' :
'−'));
// world
$sP .= (($in_Perms & 0x0004) ? 'r' : '−') .
(($in_Perms & 0x0002) ? 'w' : '−') .
(($in_Perms & 0x0001) ? (($in_Perms & 0x0200) ? 't' : 'x' )
:
(($in_Perms & 0x0200) ? 'T' :
'−'));
return $sP;
}
$file = lstat("/bin/bash");
echo TranslatePerm($file['mode']);
//(for HTML)
which lead to :
-rwxr-xr-x
the function mfunGetPerms does not return correct permissions.
for example :
$perm=fileperms("/dev/ttyS0" /*a symbolic link*/");
echo exec("ll /dev/ttyS0");
echo mfunGetPerms($perm);
echo TranslatePerm($file['mode']);
lr-xr-xr-x 1 root root 5 Oct 19 11:10 /dev/ttyS0 -> tts/0l //exec
cr-xr-xr-x //mfunGetPerms
lr-xr-xr-x //TranslatePerm
----
Manual Page -- http://www.php.net/manual/en/function.fileperms.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36883
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36883&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36883&report=yes
Search -- http://master.php.net/manage/user-notes.php