note 71315 deleted from function.ftp-rawlist by cmb
| From: | cmb@php.net | Date: | Sun, 04 Aug 2019 08:41:01 +0000 |
| Subject: | note 71315 deleted from function.ftp-rawlist by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211779@lists.php.net to get a copy of this message | ||
Note Submitter: Hazem dot Khaled at gmail dot com
----
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';
}
}
?>