0

I am using this script to show all images in a directory and to display image size, etc. I've been trying different ways (and yes, I also used Google) to sort them by date but none worked for me.

<?php
    $dir = 'uploads/';
    $files = glob("$dir*.*");
    for($i=count($files)-1; $i >= 0; $i--):
        $image = $files[$i];
        $size = getimagesize($image);
        $image_height = $size[0];
        $file_size_byte = filesize($image);
        $file_size_kilobyte = ($file_size_byte/1024);
        $file_size_kilobyte_rounded = round($file_size_kilobyte,1);

    ?>

        <div class="fileDiv" onclick="showImage('<?php echo $image; ?>','<?php echo $image_height; ?>');">
            <div class="imgDiv"><img class="fileImg lazy" data-original="<?php echo $image; ?>"></div>
            <p class="fileDescription"><?php echo $image; ?></p>
            <p class="fileTime"><?php echo date ("F d Y H:i", filemtime($image)); ?></p>
            <p class="fileTime"><?php echo $file_size_kilobyte_rounded; ?> KB</p>
        </div>

    <?php endfor; 

?>

How do I have to modify this script to sort the files by date and the last modified image to be displayed on top? Could someone please help me how to do this? Thanks so much!

moritzm3
  • 1,197
  • 1
  • 7
  • 6

0 Answers0