zoukankan      html  css  js  c++  java
  • 对上传图片像素和大小的控制

     

    上传图片,要求图片200100象素,大小小于2M,
    如果图片不符合要求,不能上传,否则上传图片,上传以后对图片按系统日期动态命名,保留路径到数据库里。

    private void Button1_Click(object sender, System.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>200 || Height>100 || 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("请选择图片文件!");
       }
      }

  • 相关阅读:
    hduoj 1865 1string 【大数】【菲波那切数列】
    poj 1664 放苹果【M的N划分】
    新年第一篇
    3、XCode: 如何添加自定义代码片段
    2、文件夹
    1、获取当前屏幕显示的页面
    运算符
    表单数据接收
    PHP进入MySQL数据库
    my SQL认识和进入
  • 原文地址:https://www.cnblogs.com/sutengcn/p/271554.html
Copyright © 2011-2022 走看看