Jump to content

[SOLVED] Check image extention


sean14592

Recommended Posts

Hi, I was suprised tofind that this has not yet been posted.

 

I need to find what the regex is to check if the file entered into  upload field has the extention .gif,.jpg,.png,.bmp ect...

 

I have tried...

/([*\.jpg]|[*\.gif]|[*\.png]|[*\.jpeg]|[*\.JPEG]|[*\.JPG]|[*\.bmp]|[*\.psd]|[*\.psp]|[*\.tif])+$/,

 

though it somehow allows me to upload files like .exe but not .dll.

 

so weird.lol

 

Please help me

Sean Preston.

Link to comment
https://forums.phpfreaks.com/topic/99798-solved-check-image-extention/
Share on other sites

Character classes only allow one character within the set to be accepted, unless a quantifier is used. I suggest making an array of these extensions, grabbing the extension, then testing it against the array (in_array).

 

lol, strange. try this:

 

/(.avi|.jpg|.png|.gif|.mpg|.divx|.mov)$/i

 

. is a metacharacter that matches anything but new lines; to get a literal period you must escape it: \.. Additionally, there's no need to repeat the periods, nor capture the data: /\.(?:avi|jpg|png|gif|mpg|divx|mov)\z/i

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.