• Notice regarding image hosts and attachments. See here.

PHP File Listing

Soldato
Joined
27 Dec 2005
Posts
17,317
Location
Bristol
What I'm trying to do is quite basic, and yet it's throwing up a load of problems.

I have a list of files...
200507July 2005.html
200508August 2005.html
200509September 2005.html
etc.

...and I want to display these as a list, but obviously earliest first. The code I'm using is:

PHP:
$path = "/";

$dir_handle = @opendir($path) or die("Unable to open $path");

while ($file = readdir($dir_handle)) 
{
    if($file!="." && $file!=".." && $file!="index.php" && $file!="inc.php"){
    $dir_array[] = $file;
    }
}

closedir($dir_handle);

$dir_reversed = array_reverse($dir_array);

foreach($dir_reversed as $key => $value){
$newfile = substr($value, 6, -5);
echo "<div class='readMoreBtn' style='margin-right:10px'><a href='$newfile'>$newfile</a></div>";
}
It seems fairly straight forward, but the result is not so much. At the moment it's returning:

Array ( [0] => 200601January 2006.html [1] => 200602February 2006.html [2] => 200510October 2005.html [3] => 200511November 2005.html [4] => 200509September 2005.html [5] => 200507July 2005.html [6] => 200508August 2005.html )

Which is fine apart from Jan/Feb and July/Aug, and I have no idea why it's putting them in this order.

Any help greatly appreciated!
 
Last edited:
it's difficult to know without having your directory listing. If you could zip/upload it, I could take a look. Basically, you just want to print_r( glob( '/*.html', GLOB_NOSORT ) ); just to see what you get and see if you can use it.
 
Directory listing is just:

index.php
content.inc.php
200801January 2008.html
200802February 2008.html
200803March 2008.html

...and so on (with the dates).
 
Back
Top Bottom