asp.net上传图片里怎么判断图片的大小?

2025-12-15 12:54:14
推荐回答(4个)
回答1:

lpath1=Server.MapPath(@"~/")+"upload"+"/"+"products"+"/"+"large"+"\\"+riqi+"."+imagetype2;//图片路径

System.Drawing.Image image2 = System.Drawing.Image.FromFile(lpath1);
if((image2.Width>520)&&(image2.Height>520))
{

image2.Dispose();
Response.Write("");
return;
}

回答2:

不让上传是不行的。只有在上传之后,通过File类的属性或方法判断文件的大小,如果太大,不保存它,并通过Response.write()方法告知窗户端了。
我是这样处理的。

回答3:

FileUpload1.PostedFile.ContentLength图片大小
FileUpload1.PostedFile.ContentType图片类型

回答4:

if (this.FileUpload1.PostedFile.ContentLength > 500 * 1024)
{
//太大了
}