note 49614 added to function.chmod
| From: | info at rvgate dot nl | Date: | Thu, 03 Feb 2005 01:12:23 +0000 |
| Subject: | note 49614 added to function.chmod | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84403@lists.php.net to get a copy of this message | ||
When using ftp_rawlist, in order to get the chmod number from the attributes, i use this code:
<?php
function chmodnum($mode) {
$realmode = "";
$legal = array("","w","r","x","-");
$attarray = preg_split("//",$mode);
for($i=0;$i<count($attarray);$i++){
if($key = array_search($attarray[$i],$legal)){
$realmode .= $legal[$key];
}
}
$mode = str_pad($realmode,9,'-');
$trans =
array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
$mode = strtr($mode,$trans);
$newmode = '';
$newmode .= $mode[0]+$mode[1]+$mode[2];
$newmode .= $mode[3]+$mode[4]+$mode[5];
$newmode .= $mode[6]+$mode[7]+$mode[8];
return $newmode;
}
?>
some examples:
drwxr-xr-x => 755
drwxr-xr-x => 755
dr-xr-xr-x => 555
drwxr-xr-x => 755
drwxr-xr-x => 755
drwxr-xr-x => 755
drwxr-xr-x => 755
drwxrwxrwt => 776
drwxr-xr-x => 755
drwxr-xr-x => 755
lrwxrwxrwx => 777
used some of already posted code...
----
Manual Page -- http://www.php.net/manual/en/function.chmod.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49614
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49614&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49614&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49614&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49614&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49614&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49614&report=yes
Search -- http://master.php.net/manage/user-notes.php