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?