note 82751 added to function.chmod

From: Date: Thu, 24 Apr 2008 12:09:50 +0000
Subject: note 82751 added to function.chmod
Groups: php.notes 
Request: Send a blank email to php-notes+get-138736@lists.php.net to get a copy of this message
Note that info at rvgate dot nl's chmodnum function produces INCORRECT results. The resutls are base-10 numbers that only LOOK like they are octal numbers. The function also ignores setuid, setgid and sticky bits, and will produce incorrect numbers if such a file is encountered. Instead, this brute-force code works. Maybe there is something more slick, but this isn't too CPU-intensive (note that it assumes you've error-checked that you indeed have a 10-character string!): $permissions = 'drwxr-xr-x'; // or whatever $mode = 0; if ($permissions[1] == 'r') $mode += 0400; if ($permissions[2] == 'w') $mode += 0200; if ($permissions[3] == 'x') $mode += 0100; else if ($permissions[3] == 's') $mode += 04100; else if ($permissions[3] == 'S') $mode += 04000; if ($permissions[4] == 'r') $mode += 040; if ($permissions[5] == 'w') $mode += 020; if ($permissions[6] == 'x') $mode += 010; else if ($permissions[6] == 's') $mode += 02010; else if ($permissions[6] == 'S') $mode += 02000; if ($permissions[7] == 'r') $mode += 04; if ($permissions[8] == 'w') $mode += 02; if ($permissions[9] == 'x') $mode += 01; else if ($permissions[9] == 't') $mode += 01001; else if ($permissions[9] == 'T') $mode += 01000; printf('Mode is %d decimal and %o octal', $mode, $mode); ---- Server IP: 64.71.164.2 Probable Submitter: 69.181.216.234 ---- Manual Page -- http://www.php.net/manual/en/function.chmod.php Edit -- https://master.php.net/note/edit/82751 Del: integrated -- https://master.php.net/note/delete/82751/integrated Del: useless -- https://master.php.net/note/delete/82751/useless Del: bad code -- https://master.php.net/note/delete/82751/bad+code Del: spam -- https://master.php.net/note/delete/82751/spam Del: non-english -- https://master.php.net/note/delete/82751/non-english Del: in docs -- https://master.php.net/note/delete/82751/in+docs Del: other reasons-- https://master.php.net/note/delete/82751 Reject -- https://master.php.net/note/reject/82751 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138736) next »