note 110803 modified in function.ftp-rawlist by aharvey
| From: | aharvey@php.net | Date: | Tue, 11 Dec 2012 01:51:26 +0000 |
| Subject: | note 110803 modified in function.ftp-rawlist by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192452@lists.php.net to get a copy of this message | ||
Here's a simple function that'll parse the data returned by ftp_rawlist() into an
associative array. I wrote it because some of the functions listed below are way to long, complex or
won't work with file names that contain spaces.
<?php
function listDetailed($resource, $directory = '.') {
if (is_array($children = @ftp_rawlist($resource, $directory))) {
$items = array();
foreach ($children as $child) {
$chunks = preg_split("/\s+/", $child);
list($item['rights'], $item['number'], $item['user'],
$item['group'], $item['size'], $item['month'], $item['day'],
$item['time']) = $chunks;
$item['type'] = $chunks[0]{0} === 'd' ? 'directory' :
'file';
array_splice($chunks, 0, 8);
$items[implode(" ", $chunks)] = $item;
}
return $items;
}
// Throw exception or return false < up to you
}
?>
--was--
Here's a simple function that'll parse the data returned by ftp_rawList() into an
associative array. I wrote it because some of the functions listed below are way to long, complex or
won't work with file names that contain spaces.
<?php
function listDetailed($resource, $directory = '.') {
if (is_array($children = @ftp_rawList($resource, $directory))) {
$items = array();
foreach ($children as $child) {
$chunks = preg_split("/\s+/", $child);
list($item['rights'], $item['number'], $item['user'],
$item['group'], $item['size'], $item['month'], $item['day'],
$item['time']) = $chunks;
$item['type'] = $chunks[0]{0} === 'd' ? 'directory' :
'file';
array_splice($chunks, 0, 8);
$items[implode(" ", $chunks)] = $item;
}
return $items;
}
// Throw exception or return false < up to you
}
?>
http://php.net/manual/en/function.ftp-rawlist.php