protected void Button1_Click(object sender, EventArgs e) { if(File1.PostedFile.ContentType.ToUpper().IndexOf("IMAGE")>-1) { System.Drawing.Image img= System.Drawing.Image.FromStream(File1.PostedFile.InputStream); int Width = img.Width; int Height = img.Height; if(Width>60 || Height>60 || File1.PostedFile.ContentLength>1024*1024*2) { Response.Write("不符:Width="+Width.ToString() +"<br>Height="+Height.ToString()+"<br>Size="+(this.File1.PostedFile.ContentLength/1024).ToString("##,##0.00")+"K"); } else { string sPath =Server.MapPath(System.DateTime.Now.ToString("yyy-MM-dd hh-mm-ss")+Session.SessionID+".jpg"); this.File1.PostedFile.SaveAs(sPath); Response.Write("上传成功"); } } else { Response.Write("请选择图片文件!"); } }
转载于:https://www.cnblogs.com/qzc900809/archive/2013/01/10/2855533.html