protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { string file = Request.Files["upload"].FileName; string s = System.IO.Path.GetExtension(file); if (Regex.IsMatch(s, @".jpg|.png|.gif|.jpeg", RegexOptions.IgnoreCase)) { if (Request.Files["upload"].ContentLength / 1024 < 5) { using (Stream stream = Request.Files["upload"].InputStream) { System.Drawing.Image image = System.Drawing.Image.FromStream(stream); if (image.Width == 150 && image.Height == 100) { Request.Files["upload"].SaveAs(Server.MapPath("~/image/") + file); } else { ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('图片长宽不对。');</script>"); } } } else { ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('图片太大。');</script>"); } } else { ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('后缀名不对。');</script>"); } } }
上传图片 验证后缀名,图片大小,尺寸。
上传图片
最新推荐文章于 2023-01-09 11:15:34 发布