note 108501 added to function.ftp-nlist
| From: | JacobSlomp | Date: | Wed, 02 May 2012 03:58:40 +0000 |
| Subject: | note 108501 added to function.ftp-nlist | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187424@lists.php.net to get a copy of this message | ||
Hi,
I wrote this function to get the file list, I tested it only with php5 with linux ftp. And works
fine for me.
it will return an array with the name, type (file/folder), owner, owner_id and rights.
<?php
function ftp_get_filelist($con, $path){
$files = array();
$contents = ftp_rawlist ($con, $path);
$a = 0;
if(count($contents)){
foreach($contents as $line){
preg_match("#([drwx\-]+)([\s]+)([0-9]+)([\s]+)([0-9]+)([\s]+)([a-zA-Z0-9\.]+)([\s]+)([0-9]+)([\s]+)([a-zA-Z]+)([\s
]+)([0-9]+)([\s]+)([0-9]+):([0-9]+)([\s]+)([a-zA-Z0-9\.\-\_ ]+)#si", $line, $out);
if($out[3] != 1 && ($out[18] == "." || $out[18] == "..")){
// do nothing
} else {
$a++;
$files[$a]['rights'] = $out[1];
$files[$a]['type'] = $out[3] == 1 ? "file":"folder";
$files[$a]['owner_id'] = $out[5];
$files[$a]['owner'] = $out[7];
$files[$a]['date_modified'] = $out[11]." ".$out[13] . "
".$out[13].":".$out[16]."";
$files[$a]['name'] = $out[18];
}
}
}
return $files;
}
?>
Greets,
Jacob
----
Server IP: 69.147.83.197
Probable Submitter: 50.93.106.216
----
Manual Page -- http://www.php.net/manual/en/function.ftp-nlist.php
Edit -- https://master.php.net/note/edit/108501
Del: integrated -- https://master.php.net/note/delete/108501/integrated
Del: useless -- https://master.php.net/note/delete/108501/useless
Del: bad code -- https://master.php.net/note/delete/108501/bad+code
Del: spam -- https://master.php.net/note/delete/108501/spam
Del: non-english -- https://master.php.net/note/delete/108501/non-english
Del: in docs -- https://master.php.net/note/delete/108501/in+docs
Del: other reasons-- https://master.php.net/note/delete/108501
Reject -- https://master.php.net/note/reject/108501
Search -- https://master.php.net/manage/user-notes.php