note 46127 deleted from function.ftp-rawlist by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 19:29:43 +0000 |
| Subject: | note 46127 deleted from function.ftp-rawlist by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217905@lists.php.net to get a copy of this message | ||
Note Submitter: ergye at yahoo dot com
----
The previous regular expression is super, but does not take simlinks into account. Change [-d] to
[-dl] and instead of indicating directories we should indicate the type of the items:
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}) (.+)", $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[8];
}
$dir_list[] = $tmp_array;
}
return $dir_list;
}
$buff = ftp_rawlist($cid, "/");
$items = itemize_dir($buff);
?>