note 71315 added to function.ftp-rawlist

From: Date: Wed, 22 Nov 2006 09:25:32 +0000
Subject: note 71315 added to function.ftp-rawlist
Groups: php.notes 
Request: Send a blank email to php-notes+get-119971@lists.php.net to get a copy of this message
that comment have 4 function the 1st function "<b>get_files</b>" get the list of files by the full bath "/www/ex/" and return 3 arrays dir = the directories in this directory with the time ,date ,more ... linke = the links in this directory with the time ,date ,more ... file = the files in this directory with the time ,date ,more ... the 2nd function "chmodnum" convert from "drwxrwxrwx" to "777" * i found it in php.net manual the 3rd function "get_size" convert from the byte to MB or GB or TB the 4th function "get_type" return if this file or directory or link the functions <?php function get_files($path = '') { if ($path == '' && !$_GET['path']) { $path = '/'; } elseif ($path == '') { $path = $_GET['path']; } //$all_folders = ftp_nlist($this->conection, $_GET['path']); $array = ftp_rawlist($this->conection, $path); if (is_array($array)) foreach ($array as $folder) { $struc = array(); $current = preg_split("/[\s]+/",$folder,9); $struc['perms'] = $current[0]; $struc['permsn']= chmodnum($current[0]); $struc['number']= $current[1]; $struc['owner'] = $current[2]; $struc['group'] = $current[3]; $struc['size'] = get_size($current[4]); $struc['month'] = $current[5]; $struc['day'] = $current[6]; $struc['time'] = $current[7]; $struc['name'] = str_replace('//','',$current[8]); //$struc['raw'] = $folder; if ($struc['name'] != '.' && $struc['name'] != '..' && get_type($struc['perms']) == "folder") { $folders[] = $struc; } elseif ($struc['name'] != '.' && $struc['name'] != '..' && get_type($struc['perms']) == "link") { $links[] = $struc; } elseif ($struc['name'] != '.' && $struc['name'] != '..') { $files[] = $struc; } } return array($folders,$links,$files); } 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; } function get_size($size) { if ($size < 1024) { return round($size,2).' Byte'; } elseif ($size < (1024*1024)) { return round(($size/1024),2).' MB'; } elseif ($size < (1024*1024*1024)) { return round((($size/1024)/1024),2).' GB'; } elseif ($size < (1024*1024*1024*1024)) { return round(((($size/1024)/1024)/1024),2).' TB'; } } function get_type($perms) { if (substr($perms, 0, 1) == "d") { return 'folder'; } elseif (substr($perms, 0, 1) == "l") { return 'link'; } else { return 'file'; } } ?> ---- Server IP: 66.163.161.117 Probable Submitter: 82.201.222.6 ---- Manual Page -- http://www.php.net/manual/en/function.ftp-rawlist.php Edit -- https://master.php.net/note/edit/71315 Del: integrated -- https://master.php.net/note/delete/71315/integrated Del: useless -- https://master.php.net/note/delete/71315/useless Del: bad code -- https://master.php.net/note/delete/71315/bad+code Del: spam -- https://master.php.net/note/delete/71315/spam Del: non-english -- https://master.php.net/note/delete/71315/non-english Del: in docs -- https://master.php.net/note/delete/71315/in+docs Del: other reasons-- https://master.php.net/note/delete/71315 Reject -- https://master.php.net/note/reject/71315 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119971) next »