First of all, I would like to say that this site is a great help, and the people who respond to this message board are great! I almost always get an answer to my questions, thanks.
I have this code that displays filenames from a folder and counts the number of files. But if I add new files into the folder, it displays the files in the order they were uploaded, not alphabetically. Can anyone help me list them alphabetically? I think I need to put them into an array and then sort them, but I don't know how to do that. Thank you very much in advance. Here is the part of the code I am using:
// IF IS A DIRECTORY, COUNT NUMBER OF PICTURES IN FOLDER
if (is_dir($DirName))
{
$Dir = opendir ($DirName);
function countFiles($anything, $dir){$num_files = 0;if (is_dir("$dir"))if ($handle = opendir($dir)){while (($file = readdir($handle)) !== false){if (is_dir("$file")){if (($file != ".") and ($file != ".." )){$num_files += countFiles($dir . "/" . $file);}}else{$num_files++;}}}return $num_files;}
$NumberOfPictures = countFiles($Dir, $DirName);
// PRINT NUMBER OF PICTURES
while ($myrow = mysql_fetch_array($result4))
{
printf("<br><br><u><b>$NumberOfPictures</b> <i>%s</i> pictures:</u><br><br>| \n", $myrow[realname]);
}
// WHILE READING DIRECTORY, PRINT LINKS TO PICTURES
while ($FileName = readdir($Dir))
{
if (($FileName != ".") && ($FileName != ".."))
{
echo "<a href=\"http://www.mysite.com/index.php?Celebrity=$Celebrity&Picture=$FileName\">$FileName</a> | \n";
}
}
echo "<br>\n";
closedir($Dir);
// END: IF IS A DIRECTORY
}