Sorry, my mistake. See the edited version. I had '$file' where I should've had '$f'... D'OH!
Oh, and there should be a backslash prior to the "." in the eregi() function; but for some reason the backslash got stripped when I copied and pasted the PHP into the post box...
if(eregi(".(jpg|gif|png)$", $f)) {
// yadadadadad
}