0

Possible Duplicate:
How to get X newest files from a directory in PHP?
Get most recent files recursively with PHP

I have a script receives the latest webcam image uploaded to www.bovicam/webcam:

<?php
$dir = 'webcam/';
$base_url = 'http://www.bovicam.com/webcam/';
$newest_mtime = 0;
$show_file = 'BROKEN';
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if (($file != '.') && ($file != '..')) {
            $mtime = filemtime("$dir/$file");
            if ($mtime > $newest_mtime) {
                $newest_mtime = $mtime;
                $show_file = "$base_url/$file";
            }
        }
    }
}

print '<img src="' .$show_file. '" alt="Current Bovicam webcam image - views across        Bovisand Bay" style="width:90%; margin-top:7%; margin-bottom:3%;" class="displayed" id="webcam_image">';
?>

I want to display the last six images in the page below the webcam. I don't have the luxury of being able to 'label' the files from the camera by date, so is there a way to do this by 'last modified' as above?

Community
  • 1
  • 1
user1721451
  • 247
  • 6
  • 15
  • Thanks for your feedback Mario - so I'd have to work out a way to label the file names in order to do this? – user1721451 Oct 22 '12 at 17:21
  • So basically use a combination of `glob()` to get an array list, fetch the `filemtime()` for each, then cut out the first 6 from the array using `array_slice()`. – mario Oct 22 '12 at 17:22
  • I'm pretty new to PHP Mario, is there anyway you may be able to provide an example? – user1721451 Oct 22 '12 at 17:24
  • I believe I can add sequential formatting to the file name, so 1, 2 3, etc, but I can't be specific in terms of date. – user1721451 Oct 22 '12 at 17:25

0 Answers0