So you don't save images names to database? In that case just check last inserted ID for that gallery. Anyway, I prefer glob to scandir:
<?php
# glob sorts only by alphabetic order, GLOB_NOSORT flag speeds up the function
$list = glob("{*.jpg,*.gif,*.png}",GLOB_BRACE|GLOB_NOSORT);
array_multisort(array_map('filemtime', $list), SORT_DESC, $list);
echo $list[0]; # get last modify time
?>
When you run stat, into a command line, to a file you get 3 different dates:
Access: 2012-01-19 00:56:04.104197718 +0100
Modify: 2012-01-13 15:54:58.000000000 +0100
Change: 2012-01-23 12:22:36.672104877 +0100
You can use fileatime, filemtime and filectime functions to get those values: each time you open an image or use touch command Access time is changed (fileatime); each time the inode information of the file is modified, like renaming, moving the file, setting new permissions the Change time is modified (filectime); last, each time the contents of a file is updated Modify time changes, so this function should be the most important for you: filemtime.
More info: http://php.net/manual/en/function.filemtime.php
Hope is helpful, bye :)