仅上传图片-图片应接受 [英] Uploading Image-Image only should accept

查看:92
本文介绍了仅上传图片-图片应接受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我只想上传图片的文件输入类型

我已经写了代码

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



即使用户尝试在IE8中将PDF或excel重命名为jpg时,它的工作状况也很好,不允许上传

但是问题是当他们使用chrome浏览器PDF文件时,将其重命名为JPG,然后接受并上传:(



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 ?

推荐答案

您可以检查前几个字节以获取实际的文件类型.

检查以下具有一些常用文件类型的链接:
http://www.garykessler.net/library/file_sigs.html [
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.


这篇关于仅上传图片-图片应接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆