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;
}
不让上传是不行的。只有在上传之后,通过File类的属性或方法判断文件的大小,如果太大,不保存它,并通过Response.write()方法告知窗户端了。
我是这样处理的。
FileUpload1.PostedFile.ContentLength图片大小
FileUpload1.PostedFile.ContentType图片类型
if (this.FileUpload1.PostedFile.ContentLength > 500 * 1024)
{
//太大了
}