josejohnson63
New Member
- Messages
- 9
- Reaction score
- 0
- Points
- 1
Here is the php script to list the files in a folder based on the modified date
Using the below script you can list files from older to latest or latest to oldest
<?php
// list from a given folder $folder="test/";
$files = glob( $folder."*.*" ); // to avoid hidden files
// Sort files by modified time, latest to oldest
array_multisort(array_map( 'filemtime', $files ),SORT_NUMERIC,SORT_DESC,$files);
// Use SORT_ASC in place of SORT_DESC for oldest to latest
//array_multisort(array_map( 'filemtime', $files ),SORT_NUMERIC,SORT_ASC,$files);
// display the file names
if(count($files)){
for( $i=0 ; $i < count($files) ; $i++ ){
echo(basename($files[$i])." <a href='".$folder.$files[$i]."'>Link to the file</a><br>");
}
}
?>
Using the below script you can list files from older to latest or latest to oldest
<?php
// list from a given folder $folder="test/";
$files = glob( $folder."*.*" ); // to avoid hidden files
// Sort files by modified time, latest to oldest
array_multisort(array_map( 'filemtime', $files ),SORT_NUMERIC,SORT_DESC,$files);
// Use SORT_ASC in place of SORT_DESC for oldest to latest
//array_multisort(array_map( 'filemtime', $files ),SORT_NUMERIC,SORT_ASC,$files);
// display the file names
if(count($files)){
for( $i=0 ; $i < count($files) ; $i++ ){
echo(basename($files[$i])." <a href='".$folder.$files[$i]."'>Link to the file</a><br>");
}
}
?>