Ok, if I remember correctly, there's a quirky little thing with readdir() in that it always will read the files in the directory from earliest creation time to most recent. So, the most recently created file would be read last.
So my (hopefully not too stupid) idea is to simply grab the last file listed using readdir(). We'll read each file and simply cheat by reassigning it to one variable -- not an array, just one variable. And assuming my theory holds true (it works fine for me), then in the end, the most recently created file name will be held in your variable, which you can then read.
<?php
$handle=opendir('.');
while ($file = readdir($handle)) {
$newestfile = $file;
}
echo "the most recently CREATED file is: <b>".$newestfile."</b>";
?>
I know, this is not the most professional of solutions. My other idea is to create an array of file name/creation time key/value pairs, then sort the times then grab the filename with the least difference to the current time(). I only wish I know how to do that 😛 Try the code above and see if it does the trick. Just remember it's looking at the creation time, not last modified.
EDIT: oh yeah... and you may have some delay with this if you have a gazillion files in there. A pic every 30 seconds does add up...so you may want to clean out the old pics now and then.