图片上传为什么文件格式无法用ContentType获取?
我的代码是这样的:
a.aspx:
<form id="Form1" name="Form1" method="post" runat="server" >
<INPUT type="file" size="50" name="file1" id="file1" style="WIDTH:300px" runat="server">
</form>
b.aspx.cx:
if (TestPostFiles() == true)
{}
private bool TestPostFiles()
{
HttpPostedFile ImgFile = Request.Files["file1"];
string [] PicType=new string[]{".gif",".jpg",".jpeg",".png"};
string UpFileType=ImgFile.ContentType.ToLower();
int cnt=0;
for(int x=0;x<PicType.Length;x++)
{
if(UpFileType==PicType[x])
{
cnt++;
break;
}
}
if(cnt<1)
{
Response.Write("<script>alert('图片格式不支持');history.go(-1)</script>");
return false;
}
else
{
return true;
}
}
虽然文件能正常保存,其他都正常,就是格式得不到.无论我上传任何格式的东西,包括jpg..得到的UpFileType始终是:总是的到:是"application/octet-stream"
这是为什么?请高手帮忙!!!