学习asp.net近一年时间了,最近开始试着做一些小项目,用fileupload控件上传图片的时候需要验证图片类型。发现IE和firefox中返回的文件类型不一样,
string fileType = "";
fileType = FupImage.PostedFile.ContentType;
在上传jpeg/png/gif图片的时候返回的类型分别为:
ie: "image/pjpeg" ,"image/x-png","image/gif"
firefox:"image/jpeg","image/png","image/gif"

所以验证文件类型的代码变成了:
f (fileType == "image/pjpeg" || fileType == "image/x-png" || fileType=="image/png" || fileType == "image/gif" || fileType=="image/jpeg")
{
//代码开始
}
{
//throw
}

相关文章:

  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-04-07
  • 2021-11-22
  • 2021-12-05
猜你喜欢
  • 2021-08-01
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2022-02-11
  • 2021-08-27
相关资源
相似解决方案