protected void btnupload_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) { Label3.Text = "温馨提示:你上传的头像尺寸不符合要求,请重新选择图片(图片大小:60*60)!"; } else { string sPath = Server.MapPath(System.DateTime.Now.ToString("yyy-MM-dd") + Session.SessionID + ".jpg"); this.File1.PostedFile.SaveAs(sPath);
Label3.Text = "恭喜你,头像上传成功!"; } } else { Response.Write("请选择图片文件!"); }
string filename = this.File1.PostedFile.FileName;
filename = DateTime.Now.Ticks.ToString() + filename.Substring(filename.LastIndexOf(".")); this.File1.PostedFile.SaveAs(Server.MapPath("upload") + "\\" + filename);
// Page.ClientScript.RegisterStartupScript(this.GetType(), "asdf", "alert('您上传的图片太大了')", true);
StringBuilder sb = new StringBuilder(); content1.InnerHtml += sb.Append("<img src=\"upload/" + filename + "\" />").ToString(); }
转载于:https://www.cnblogs.com/qzc900809/archive/2013/05/20/3089588.html
相关资源:数据结构—成绩单生成器