This is a follow up to a previous post http://sheldon.lendrum.co.nz/clean-dynamic-directory-listing-with-php_206/04/ that will Dynamically display the files in a set directory.
In this version the files can be ordered by the date that they were last modified. I will also explain how to order both Ascending and Descending by the date the file was created also.
< ?php // EAMPLE USAGE // SHOWS THE 10 NEWEST .php FILES IN A UNORDERED LIST echo("
- ". direcotryList("10","./",".php","
- "," \n") .""); // SHOWS ALL JPG IMAGES AS THUMBNAILS echo(direcotryList("","./images/",".jpg","\n")); ?>
< ?php // DIRECTORY DISPLAY USING GLOB SORTNG BY LAST MIDIFIED FILE DATE. // IF ALL PERIMATORS ARE EMPTY WILL SCAN DEFAULT DIRECTORY // '$display' => AMOUNT OF RECORDS TO DISPLAY // '$path' => PATH TO DIRECOTRY TO SCAN // '$ext' => FILES EXT, IF YOU WANT OT ECLUDE IT, OR ONLY SCAN FOR ONE TYPE OF FILE // '$start' => APPEND TO START OF OUTPUT LINE EG: '
To order the directory by Creation time rather than the current Modified date Alter line 17 to filectime.
$filemtime = filectime($v);
Currently the output is orders Newest to Oldest, to reverse the Order, change the Constant in the array_multisort on line 19.
array_multisort($filemtime, SORT_DESC, $files);
If you have any comments or suggestions, please ask below.