上传图片

来源:互联网 发布:matlab在矩阵运算实例 编辑:程序博客网 时间:2024/04/29 06:44
    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>");            }        }    }


上传图片 验证后缀名,图片大小,尺寸。	
				
		
原创粉丝点击