...

View Full Version : Resolved How do I make is display ASC



Feckie
01-30-2012, 04:44 PM
I have this script that displays folder content,
How do I make is display ASC, at the moment there is no order.



<?
/**
* Change the path to your folder.
* This must be the full path from the root of your
* web space. If you're not sure what it is, ask your host.
*
* Name this file index.php and place in the directory.
*/
// Define the full path to your folder from root
$path = "/home/xxxx/public_html/Links";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
while ($file = readdir($dir_handle)) {

if($file == "." || $file == ".." || $file == "index.php" )

continue;
echo "<a href=\"XXXXXX/Links/$file\" target=\"_blank\">$file</a><br />";

}
// Close
closedir($dir_handle);
?>

Fou-Lu
01-30-2012, 05:02 PM
Use a glob instead of opendir/readdir. I'm quite sure that one sorts by default.
Glob will return an array as well, so you may want to capture it completely so you can use a sort on the array itself prior to iterating. This would work for doing desc sorts too.

Feckie
01-30-2012, 07:22 PM
Use a glob instead of opendir/readdir. I'm quite sure that one sorts by default.
Glob will return an array as well, so you may want to capture it completely so you can use a sort on the array itself prior to iterating. This would work for doing desc sorts too.

Thanks that's sorted it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum