Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP Gallery sorting by newest file
#1
Php Gallery

Found this neat php gallery, but im trying to get it to display the newest pictures first. The files are already being named by date so i think this should be doable. By newest picture i mean by creation time. And i would really appreciate some help here.

Found some posts about it referring to this function, but im struggling to incorporate it.
function get_files($images_dir,$exts = array('jpg')) {
$files = array();
$times = array();
if($handle = opendir($images_dir)) {
    while(false !== ($file = readdir($handle))) {
        $extension = strtolower(get_file_extension($file));
        if($extension && in_array($extension,$exts)) {
            $files[] = $file;
            $times[] = filemtime($images_dir . '/' . $file);
        }
    }
    closedir($handle);
}
array_multisort($files, SORT_DESC, $times);
return $files;
}
Reply
#2
Is this more related to Python than it looks at first glance? Or did you post on the wrong forum?
Reply
#3
You sir are absolutely right, wrong forum indeed. lol
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020