i don't think file size is really an issue as i believe the read directory functions only look at names and don't load files.
here is something that would work for one directory, .. but you may have to do a little research to have this work recursively through the underlying directories:
<?
$handle=opendir("path/to/directory");
// read and loop through directory
while ($each = readdir($handle))
{
// test if it is a directory
if(!is_dir($each))
{
if( strstr($each,".jpg") || strstr($each,".gif") )
// database logic here
}
}
?>