note 82752 added to function.ftp-rawlist
| From: | paulmaybeatsquirrelmailorg at osu1 dot php dot net | Date: | Thu, 24 Apr 2008 12:13:58 +0000 |
| Subject: | note 82752 added to function.ftp-rawlist | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138737@lists.php.net to get a copy of this message | ||
Regarding converting permissions from symbolic notation to octal, note that Hazem dot Khaled at
gmail dot com'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.ftp-rawlist.php
Edit -- https://master.php.net/note/edit/82752
Del: integrated -- https://master.php.net/note/delete/82752/integrated
Del: useless -- https://master.php.net/note/delete/82752/useless
Del: bad code -- https://master.php.net/note/delete/82752/bad+code
Del: spam -- https://master.php.net/note/delete/82752/spam
Del: non-english -- https://master.php.net/note/delete/82752/non-english
Del: in docs -- https://master.php.net/note/delete/82752/in+docs
Del: other reasons-- https://master.php.net/note/delete/82752
Reject -- https://master.php.net/note/reject/82752
Search -- https://master.php.net/manage/user-notes.php