# note not sure where the file extension is within param, # I am assuming at end of string, anchoring the regex # to the end will speed it up slightly $regex = '\.(gif|jpg|jpe[g]?|jfif)(\s+|)$'; if ($filename !~ /$regex/o) { error("Your image needs to be in GIF or JPEG format."); }