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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.