zoukankan      html  css  js  c++  java
  • 限制用户上传图片大小

    protected void filePhoto_FileSelected(object sender, EventArgs e)
            {
                if (filePhoto.PostedFile.ContentType.ToUpper().IndexOf("IMAGE") > -1)
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(filePhoto.PostedFile.InputStream);
                    int Width = img.Width;
                    int Height = img.Height;
                    if (Width > 250 || Height > 350 || filePhoto.PostedFile.ContentLength > 1024 * 1024 * 2)
                    {
                        Alert.Show("不符合上传要求");
                        //Response.Write("不符:Width=" + Width.ToString() + "<br>Height=" + Height.ToString() + "<br>Size=" + (this.filePhoto.PostedFile.ContentLength / 1024).ToString("##,##0.00") + "K");
                    }
                    else
                    {
                            string fileName = txtNo.Text.Trim() + ".jpg";
                            filePhoto.SaveAs(Server.MapPath("~/Resources/upload/" + fileName));
                            imgPhoto.ImageUrl = "~/Resources/upload/" + fileName;
                            // 清空文件上传组件
                            filePhoto.Reset();
                    }
                }
                else
                {
                    Alert.Show("请选择图片文件!");
                }
            }
  • 相关阅读:
    list tuple dict 方法
    字典的方法
    看不懂的缩写
    canvas画图
    DOM2和DOM3
    表单脚本
    事件
    DOM扩展
    DOM
    BOM
  • 原文地址:https://www.cnblogs.com/hlfei/p/3675077.html
Copyright © 2011-2022 走看看