开发者

what is regular expression required to validate images

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 us开发者_Python百科er tryis to upload thier files rather than this

any solution would be great thank you


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜