My ip cam uploads timestamped images. I only want the latest so I rename all the images in a directory to webcam.jpg. I call it every hour with a cron job -only the first image uploaded after the most recent cron is left. Although this is crude, it works
If you want anything more elaborate you'll have to read the filenames into an array and reverse the array to get the latest file & rename that.
<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && preg_match("/jpg$/",$file) && $file !="webcam.jpg") {
rename($file, 'webcam.jpg');
}
}
closedir($handle);
}
?>
Hope this helps