I have quite a few PHP web pages that list directory files of a Unix system with opendir and readdir functions. Everything works fine, but the files are displayed in the order they were created.
I would like to sort them alphabetically. What should I do?
Here's the code for the page:
$current_dir = "/export/home/apache/htdocs/security";
$dir = opendir($current_dir);
if ($current_dir = opendir('.')) {
while (false !== ($file = readdir($dir))) {
if ($file != "." && $file != "..") {
print ("<p><a href=security/$file>$file</a></p>\n");
}
}
closedir($dir);
}
Thanks
Peter S.