Dear Members,
The below code spits out the top thirty files in a directory as such:
100607.htm
100507.htm
100407.htm
100307.htm
100207.htm
100107.htm
...etc until a total of 30 file names are outputed.
Is there a way to output: Oct 01, 2007 -instead of- 100107.htm
Making it a hyperlink to 100107.htm of course.
I'm thinking I have to split the filename into sections
10 01 07 .htm and then have the number 10 = Oct; 11 = Nov etc.
I'm a noob at this so any and all help is much appreciated!!!!
<?php
//define the path as relative
$path = "/home/abc/public_html/filepath";
//using the opendir function
$dir= @opendir($path) or die("Error 10011");
//reads the current directory
while (false !== ($file = readdir($dir))) {
$fileList[] = trim($file); //add the file to an array to be sorted
}//end while
rsort ($fileList); //sorts the filelist array in reverse order
reset ($fileList); //go back to the top of the array
$output = array_slice ($fileList, 0, 30, true); //$output is new array
foreach ($output as $val) {
echo "<a href=\"filepath/$val\">" . $val . "</a><br />"; //print the list.
}
//closing the directory
closedir($dir);
?>