I'm pretty new to php so I doubt this is the best way, but it should work providing you have proper permissions.
you can run the open directory comman for your image directory grab the image file names ending with the extension your looking for (.gif or .jpg, etc) and see one matches the name your looking for. Like I said, this is probalby is not the best way, especially if you have lots of images, but hopefully it helps