Originally posted by LordShryku
You wanna hand him all of the code, go ahead....
🙂 Hey, just trying to save some time... I don't want to be accused of trying to pad my post count... LOL. (No offense Ace, but I could see where this was heading without giving out the code straight up...)
Now, onto your question Ace, I am going to repost the code, commented this time, so you can see what's going on...
<?
$path = "../flashfiles/"; // Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path"); // Loop through the files
// Creates an empty array we are going to fill with file names later. It's this array that we use later to sort the filenames and output them alphabetically.
$filearray = array();
// Loop through each file name.
while ($file = readdir($dir_handle))
{
if($file == "." || $file == ".." || $file == "index.php" )
continue;
// While looping through each file name, we are putting them into the array we defined earlier, one by one. This line is actually addeacg each file name to the $filearray array.
$filearray[] = $file;
} // Close
closedir($dir_handle);
// OK, so now we have our filled array, so we need to sort it and output the names, so that's where this bit comes in. Obviouisly, we sort it first.
sort($filearray);
// This bit of code wasn't there before, but I am adding it so you can see what the array looks like now, after we filled it and sorted it...
print_r($filearray);
// Then we run through each newly sorted file name, and output it. (It's what you were doing in your earlier code, only we sorted the names first.) This basically states that for each filename in the $filearray, we are going to reference it with the $file variable. We will then use that variable to echo our links.
FOREACH($filearray as $file){
echo "<a href=\"$file\">$file</a><br />";
}
?>
I hope this explains it well enough for you, and doesn't confuse you more.