Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

file input type i wants to upload only image

i have written code
if (hpf.ContentType.ToLower() != "image/pjpeg" && hpf.ContentType.ToLower() != "image/x-png" && hpf.ContentType.ToLower() != "image/gif" && hpf.ContentType.ToLower() != "image/bmp" && hpf.ContentType.ToLower() != "image/jpg" && hpf.ContentType.ToLower() != "image/png" && hpf.ContentType.ToLower() != "image/jpeg")


its working fine even when user tries to rename PDF or excel as jpg also in IE8 its not allowing to upload

But problem is when they use chrome browser PDF file they rename it as JPG its accepting and gets upload :(

How to solve this ?
Posted

1 solution

You can inspect the first few bytes to get the actual file type.

Check the following link which has some commonly used file types:
http://www.garykessler.net/library/file_sigs.html[^]

You can then match those bytes with the one uploaded.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900