Change Picture By Most Recent In Folder

Asus / P5KPL-CM
November 24, 2009 at 01:31:43
Specs: Windows 7 Ultimate x64, 4.00GB

I would like to know how I would display a image on a website that changes when ever a newer file (.jpg) is created. Example.

I have set up a webcam that detects movement and captures series of images into a folder, I want the most recent picture that was taken in the folder displayed onto my website.

What would be the best approach to this? Javascript? PHP?

See More: Change Picture By Most Recent In Folder

Report •

December 4, 2009 at 19:30:20
php would *probably* be the better choice since it can calculate a file's timestamp and determine which is newer. A basic example using filemtime.

   $newest = -1;
   $fn = "";


   foreach(glob("images/*.jpg") as $filename) {
      if(filemtime($filename) > $newest) {
         $newest = filemtime($filename);
         $fn = $filename;

   echo $fn . "     " . $newest;

The downside, you'd either need to refresh the page with a metarefresh or just wait until it's loaded. Javascript can help out there though via ajax. Using the setInterval function, you could send a request to the php page and retrieve the file name of the most recent image.


Report •

December 9, 2009 at 21:10:03

Very good. Thanks!

Report •

Related Solutions

Ask Question