hey guys, i'm connecting to a ftp-server and displaying all items in a list. i want that list to be ordered alphabetically.
shouldn't that do it?
// get contents of the current directory
$contents = ftp_nlist($conn_id, $path);
sort($contents);
that's a part of the script!
// get contents of the current directory
$contents = ftp_nlist($conn_id, $path);
sort($contents);
print "<ul class='server_list'>";
foreach ($contents as $value) {
$line = str_replace($path, "", $value);
$ext = pathinfo($line, PATHINFO_EXTENSION);
if (strlen($ext) > 0) { //File
print "<li class='file'>";
print "<a href='d.php/?p=". $path . $line."'>$line</a>";
print "</li>";
} else { //Folder
print "<li class='folder'>";
print "<a href='?p=". $path . $line."'>$line</a>";
print "</li>";
}
}
print "</ul>";
moreover i'd like to have all folders at the top. so all folders should be ordered alphabetically and afterwards all files should be listed in abc...
print_r($contents)
before the sorting gives me:
Array (
[0] => /userupload/OrderNo_100750_HT
[1] => /userupload/README.txt
[2] => /userupload/anotherfolder
[3] => /userupload/avatar.jpg
[4] => /userupload/subfolder1
)