note 80166 added to function.ftp-rawlist
| From: | webmaster at weltvolk dot de | Date: | Wed, 02 Jan 2008 10:14:41 +0000 |
| Subject: | note 80166 added to function.ftp-rawlist | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134655@lists.php.net to get a copy of this message | ||
How to get the file list in alphabetical order with all directories at the top:
<?php
//1. Function to split ftp_rawlist() information array element
function parse_rawlist($array) {
foreach ($array as $v) {
$info = array();
$vinfo = preg_split("/[\s]+/", $v, 9);
if ($vinfo[0] !== "total") {
$info['chmod'] = $vinfo[0];
$info['num'] = $vinfo[1];
$info['owner'] = $vinfo[2];
$info['group'] = $vinfo[3];
$info['size'] = $vinfo[4];
$info['month'] = $vinfo[5];
$info['day'] = $vinfo[6];
$info['time'] = $vinfo[7];
$info['name'] = $vinfo[8];
$rawlist[$info['name']] = $info;
}
}
return $rawlist;
}
//2. Separation of files and folders
$ftp_rawlist = ftp_rawlist($ftp_connect, ".");
//Use parse_rawlist()
$rawlist = parse_rawlist($ftp_rawlist);
//One array for the directories, one for the files
$dir = array();
$file = array();
foreach ($rawlist as $k => $v) {
//Identify data type by the data permissions
if ($v['chmod']{0} == "d") {
$dir[$k] = $v;
} elseif ($v['chmod']{0} == "-") {
$file[$k] = $v;
}
}
//3. HTML output
echo "<table>";
//Directories
foreach ($dir as $k => $v) {
echo "<tr><td>[ $k ]</td><td>" . $v['chmod'] .
"</td><td>" . $v['owner'] . "</td><td";
if (count($file) > 0) {
echo " colspan=\"2\">";
} else {
echo ">";
}
echo "" . $v['group'] . "</td><td>" .
$v['month'] . " " . $v['day'] . " " . $v['time'] .
"</td></tr>";
}
//Files
foreach ($dir as $k => $v) {
echo "<tr><td>$k</td><td>" . $v['chmod'] .
"</td><td>" . $v['owner'] . "</td><td>" .
$v['group'] . "</td><td>" . $v['size'] . "
Byte</td><td>" . $v['month'] . " " . $v['day'] .
" " . $v['time'] . "</td></tr>";
}
echo "</table>";
?>
Result looks like:
[ a_directory ] drwxr-xr-r user nobody Dec 31 20:59
[ b_directory ] drwxr-xr-r user nobody Dec 31 20:59
[ c_directory ] drwxr-xr-r user nobody Dec 31 20:59
...
a_file.htm -rw-r--r-- user nobody 36817 Byte Dec 31 20:59
b_file.htm -rw-r--r-- user nobody 36817 Byte Dec 31 20:59
c_file.htm -rw-r--r-- user nobody 36817 Byte Dec 31 20:59
...
----
Server IP: 195.184.96.15
Probable Submitter: 134.245.95.14
----
Manual Page -- http://www.php.net/manual/en/function.ftp-rawlist.php
Edit -- https://master.php.net/note/edit/80166
Del: integrated -- https://master.php.net/note/delete/80166/integrated
Del: useless -- https://master.php.net/note/delete/80166/useless
Del: bad code -- https://master.php.net/note/delete/80166/bad+code
Del: spam -- https://master.php.net/note/delete/80166/spam
Del: non-english -- https://master.php.net/note/delete/80166/non-english
Del: in docs -- https://master.php.net/note/delete/80166/in+docs
Del: other reasons-- https://master.php.net/note/delete/80166
Reject -- https://master.php.net/note/reject/80166
Search -- https://master.php.net/manage/user-notes.php