Here is the code I am using. <?php $count = 0; if ($handle = opendir('./../downloads/nes')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") {$count++; print("<a href=\"".$file."\">".$file."</a><br />\n"); } } echo '<br /><br /><a href="..">Return</a>'; closedir($handle); } ?> PHP: Why does it not show my results in alphabetical order, and how can I make it do so? I'm trying to create a download script for my site, so that I just upload the files to a directory, and they automatically show up. Any help is appreciated.
assign them to an array instead of outputting, then sort($array) and output your HTML from the array. Dan
From your code it should be display your download file in alphabetical order. But if it doesn't sort then try this code. if ($handle = opendir('./../downloads/nes')) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $file_name[] = basename($file); } } sort($file_name); foreach($file_name as $download_file){ print("<a href=\"".$download_file."\">".$download_file."</a><br />\n"); } echo '<br /><br /><a href="..">Return</a>'; closedir($handle); } PHP: