Hey all, I need some help ^^;;

I want to store my images in the database then display it in a gallery.
The image schema is: Image(id, name)

The way I thought of is to connect to database and extract the image name, (eg. rose). Then I will echo it out

echo "<img src=images/$name.jpg></img><br>";

But what happens if my images have different extensions? like .gif, .png, .bmp. How am I suppose to display my images?
How do I extract the extension?

I can't manually store the extension names because it's not me who is uploading the pictures. I am doing a web application which allows users to upload their images and I dont expect them to type in the image extension in a different field everytime they want to upload sth.

Help guys, thanks! ^^;;