checking a file extension


if someone puts in:

I want it to say:

You can only use picture files as your avatar!

So i wanna check if the last part of the string is either: .gif, .jpg, .png, etc.

How do i do this?


regrex, substr(), or even explode might be helpful


naming functions isnt much help. I want to know specifically how to actually DO it. thanks anyway.


if this is for an uploaded file why not use the ACCEPT attribute of the INPUT tag? Granted I am getting the info from an old book so I don’t know if it is currently being used, obsolete, or not supported and I personally have never used it. Just giving options.

And as for the functions… it was to give you a direction to research not to tell you how to do it (I rarely tell someone how to do something - hints and direction are usually all that is needed). If you don’t know how to do it then try to come up with a way (start at the beginning, start at the end, breaking it up, checks, whatever). We are more then happy to help you out with the logic.

Good luck.


I’ll show you how to DO it for $65 an hour. Unless you wanna pay then goal of this board is to guide people, not do the work for them. if you want a prebuilt solution then look at or search google. If that won’t work then I guess it’s DIY. Everyone one help you out, but I think I speak for most people when I say “We wont write a script for you.”


maybe so, but I’ve gotten much better help before.


Guess you can’t win them all.