note 74116 deleted from function.chmod by bobby
| From: | bobby@php.net | Date: | Mon, 26 Mar 2007 14:45:35 +0000 |
| Subject: | note 74116 deleted from function.chmod by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124816@lists.php.net to get a copy of this message | ||
Note Submitter: Ambriel Angel at www dot ambriels dot net/entry
----
Two Notes:
CORRECTION:
please note my following notes were incorrect:
# Public Read = 0004 (4) , Write = 0002 (2), Execute = 0001 (1)
# Group Read = 0040 (32) , Write = 0020 (16), Execute = 0010 (8)
# World Read 0400 (256), Write 0200 (128), Execute 0100 (64)
should be
# User Read = 0400 (256), Write = 0200 (128), Execute = 0100 (64)
# Group Read = 0040 (32), Write = 0020 (16), Execute = 0010 (8)
# Public Read = 0004 (4), Write = 0002 (2), Execute = 0001 (1)
and here is an extended "getmod" function
// Get file permissions supported by chmod
function getmod($filename) {
$val = 0;
$perms = fileperms($filename);
// Owner; User
$val += (($perms & 0x0100) ? 0x0100 : 0x0000); //Read
$val += (($perms & 0x0080) ? 0x0080 : 0x0000); //Write
$val += (($perms & 0x0040) ? 0x0040 : 0x0000); //Execute
// Group
$val += (($perms & 0x0020) ? 0x0020 : 0x0000); //Read
$val += (($perms & 0x0010) ? 0x0010 : 0x0000); //Write
$val += (($perms & 0x0008) ? 0x0008 : 0x0000); //Execute
// Global; World
$val += (($perms & 0x0004) ? 0x0004 : 0x0000); //Read
$val += (($perms & 0x0002) ? 0x0002 : 0x0000); //Write
$val += (($perms & 0x0001) ? 0x0001 : 0x0000); //Execute
// Misc
$val += (($perms & 0x40000) ? 0x40000 : 0x0000); //temporary file (01000000)
$val += (($perms & 0x80000) ? 0x80000 : 0x0000); //compressed file (02000000)
$val += (($perms & 0x100000) ? 0x100000 : 0x0000); //sparse file (04000000)
$val += (($perms & 0x0800) ? 0x0800 : 0x0000); //Hidden file (setuid bit) (04000)
$val += (($perms & 0x0400) ? 0x0400 : 0x0000); //System file (setgid bit) (02000)
$val += (($perms & 0x0200) ? 0x0200 : 0x0000); //Archive bit (sticky bit) (01000)
return $val;
}