Author Topic: How to display latest image  (Read 4421 times)

Offline keithleboutillier

  • New member
  • *
  • Posts: 4
How to display latest image
« on: June 14, 2015, 04:24:14 AM »
Hi

I am receiving the Meteor sat weather images and want to automatically put them on my website.

I am looking for help and advice on the best way to do this.
each image as a different file name  ending .jpg at the moment i hand code the name into the right place on the web page so the image is displayed but i want to do this automatically.
Is there a way of getting the image displayed by using date / time and a wildcard to load the most recent image

Hope this make sense

Regards

Keith   

Offline keithleboutillier

  • New member
  • *
  • Posts: 4
Re: How to display latest image
« Reply #1 on: June 15, 2015, 04:50:32 PM »
I think i have worked this out maybe not the best code ever written but it works for me
This PHP code will look in the specified directory and display the latest images
 
<?php
 $images = glob('../weather/meteor/'.'*.{jpg}', GLOB_BRACE); //formats to look for
   
         $num_of_files = 3; //number of images to display

    foreach($images as $image)
    {
         $num_of_files--;

         if($num_of_files > -1) //this made me laugh when I wrote it
           echo "<b>".$image."</b><br>Created on ".date('D, d M y H:i:s', filemtime($image)) ."<br><img src="."'".$image."'style='width: 100%'"."><br><br>" ; //display images
         else
           break;
    }
?>