Help with simple PHP script

wetwillabee

Veteran XV
I want a simple directory list accessible online. I found a php script, but I want the files to be displayed in numerical/alphabetical order. Someone smarter than me please modify this script to do what I want.

Code:
<?php
$path = ".";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
    if($file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin" && $file != ".ftpquota") {
        echo "<a href='$path/$file'>$file</a><br /><br />";
        $i++;
    }
}
closedir($dh);
?>
 

Read that. I don't have an array function in my script. I'm clueless when it comes to programming. If you just give me a new function/line of code, I don't know where to add it to mine/what else to put, etc. I need hand holding. I'm sure this is a very simple bit of script for someone who does this all the time.
 
winner is borlak

default sort order for scandir is alphabetically ascending
 
I want a simple directory list accessible online. I found a php script, but I want the files to be displayed in numerical/alphabetical order. Someone smarter than me please modify this script to do what I want.

Code:
<?php
$path = ".";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
    if($file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin" && $file != ".ftpquota") {
        echo "<a href='$path/$file'>$file</a><br /><br />";
        $i++;
    }
}
closedir($dh);
?>

Php lol.
 
Back
Top