Jump to content

[SOLVED] ordering by filetime


MikeDXUNL

Recommended Posts

<?php
$folder = realpath('path/to/folder');
$files = array();
$times = array();
foreach(scandir($folder) as $file){
  if(is_file($folder.'/'.$file)){
    $files[] = $file;
    $times[] = filemtime($folder.'/'.$file);
  }
}
array_multisort($times,$files);
print_r($files);
?>

well, it works. but when i upload a file... say i have

 

photo1.jpg

photo2.jpg

 

already uploaded...

 

then i upload

 

photo3.jpg

 

i need it to be

photo3.jpg, photo2.jpg, photo1.jpg

 

in that order...

 

when i run your script; it gives me photo1.jpg, photo2.jpg, photo3.jpg

<?php
$folder = realpath('path/to/folder');
$files = array();
$times = array();
foreach(scandir($folder) as $file){
  if(is_file($folder.'/'.$file)){
    $files[] = $file;
    $times[] = filemtime($folder.'/'.$file);
  }
}
array_multisort($times,SORT_DESC,$files); //Added Descending Here
print_r($files);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.