tags:

views:

74

answers:

3

hi, i trying to upload images to folder. here i need to upload only images like .JPEG|.jpeg|GIF|.gif|.PNG|.png|bmp|.BMP

what is expression that we should write here so that when ever user tryis to upload thier files rather than this

any solution would be great thank you

+4  A: 

Generally that's a bad idea, but...

/(jpg|gif|bmp|png)$/

Run the expression with whatever language you're using and make sure you make it case insensitive.

I say it's a bad idea, because you're better off checking the actual data in the file after the upload occurs. I can rename a file to anything I want and upload it to your site.

ETA: the forward slashes may be optional in your language.

Langdon
+1 for pointing out the hole big enough to drive a truck through :-) And I've seen .jpeg files as well, whether you want to cover those is a matter of taste - I'd rather ditch the file name checking altogether as you suggest.
paxdiablo
+1  A: 

I think it should work with:

\w*.(jpg|jpeg|gif|png|bmp)$ Using this, you need to use IgnoreCase in asp.net.

\w are all alphanumeric characters followed by a dot (escaped because it is a special character). Then one of your extensions.

But remember: Files are not identified by their extension, but by their content. You might be able to use something alike to linux "file" utility for identifying the type of file. I don't know if something similar exists for asp.net

data
A: 

you can try this..

(.*\.([Gg][Ii][Ff])|.*\.([Jj][Pp][Gg])|.*\.([Bb][Mm][Pp])|.*\.([pP][nN][gG])|.*\.([tT][iI][iI][fF])$)
Muhammad Akhtar