note 47677 deleted from function.ftp-rawlist by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 19:29:26 +0000 |
| Subject: | note 47677 deleted from function.ftp-rawlist by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217904@lists.php.net to get a copy of this message | ||
Note Submitter: Jonathan Almarez
----
To make the latest correction to the parsing code:
"ergye at yahoo dot com" dosen't take into account for files or directories that are
older than a year where instead of showing the time, it shows the year.
The code below not only parses:
drwxrwxr-x 2 503 503 4096 Dec 3 12:12 CVAR
It also parses:
drwxrwxr-x 2 503 503 4096 Dec 3 2003 CVAR
0 = file
1 = directory
2 = simlink
<?php
function itemize_dir($contents) {
foreach ($contents as $file) {
if(ereg("([-dl][rwxst-]+).* ([0-9]) ([a-zA-Z0-9]+).* ([a-zA-Z0-9]+).* ([0-9]*)
([a-zA-Z]+[0-9: ]*[0-9])[ ]+(([0-9]{2}:[0-9]{2})|[0-9]{4}) (.+)", $file, $regs)) {
$type = (int) strpos("-dl", $regs[1]{0});
$tmp_array['line'] = $regs[0];
$tmp_array['type'] = $type;
$tmp_array['rights'] = $regs[1];
$tmp_array['number'] = $regs[2];
$tmp_array['user'] = $regs[3];
$tmp_array['group'] = $regs[4];
$tmp_array['size'] = $regs[5];
$tmp_array['date'] = date("m-d",strtotime($regs[6]));
$tmp_array['time'] = $regs[7];
$tmp_array['name'] = $regs[9];
}
$dir_list[] = $tmp_array;
}
return $dir_list;
}
$buff = ftp_rawlist($cid, "/");
$items = itemize_dir($buff);
?>