Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am using the following PHP script to list the contents on a folder called "minutes."
<?php
if ($handle = opendir('./minutes/')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$thelist .= ''.$file.'
';
}
}
closedir($handle);
}
?>Is there a simple way to have the list that is returned sorted by the date the file was modified?
-Ryan Adams
http://RyanTAdams.com

Here is a solution that, based on the archaic PHP3-style example code, is most likely better than what the OP came up with. ;)
// Grab all files from the desired folder
$files = glob( './minutes/*.*' );// Sort files by modified time, latest to earliest
// Use SORT_ASC in place of SORT_DESC for earliest to latest
array_multisort(
array_map( 'filemtime', $files ),
SORT_NUMERIC,
SORT_DESC,
$files
);// do whatever you want with $files
print_r( $files );

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |