sean14592 Posted April 6, 2008 Share Posted April 6, 2008 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 More sharing options...
uniflare Posted April 6, 2008 Share Posted April 6, 2008 lol, strange. try this: /(.avi|.jpg|.png|.gif|.mpg|.divx|.mov)$/i Link to comment https://forums.phpfreaks.com/topic/99798-solved-check-image-extention/#findComment-510423 Share on other sites More sharing options...
effigy Posted April 7, 2008 Share Posted April 7, 2008 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 https://forums.phpfreaks.com/topic/99798-solved-check-image-extention/#findComment-511183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.