note 91029 deleted from function.ftp-rawlist by danbrown
| From: | danbrown@php.net | Date: | Thu, 21 May 2009 14:48:49 +0000 |
| Subject: | note 91029 deleted from function.ftp-rawlist by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155841@lists.php.net to get a copy of this message | ||
Note Submitter: mikr
----
@francois frao_o
Your code works as long as every file in the directory (and it's parent directory) have been
created within the last year. But if not, then it fails. The following works better (mod_time will
either result as Mth dd YYYY or Mth dd HH:mm). Also, the regex is tighter now.
<?php
$list = @ftp_rawlist($con, $directory) ;
$files = array() ;
foreach ($list as $file) {
// I've commented the replace to better show what
// it's trying to do.
preg_replace(
'`^(.{10}+)'. // rights
'\s+'.
'(\d+)'. // number
'\s+'.
'(\d+|\w+)'. // owner
'\s+'.
'(\d+|\w+)'. // group
'\s+'.
'(\d+)'. // size
'\s+'.
'([a-zA-Z]{3})'. // Mon
'\s+'.
'([0-9]+)'. // dd
'\s+'.
'([0-9]{2}:?[0-9]{2})'. // YYYY or HH:MM
'\s+'.
'(.+)$`Ue',
'$files[]=array('.
'"rights" => "$1",'.
'"number" => "$2",'.
'"owner" => "$3",'.
'"group" => "$4",'.
'"file_size"=> "$5",'.
'"mod_time" => "$6 $7 $8",'.
'"file" => basename("$9"),'.
'"type" => print_r('.
'(preg_match("/^d/","$1"))?"dir":"file",1));',
$file);
}
?>