您当前的位置: 首页 > 

上传图片,要求图片200100象素,大小小于2M

发布时间:2004-10-26 19:27:00 ,浏览量:0

作者:网际浪子专栏(曾用名littlehb)  http://blog.csdn.net/littlehb/ 上传图片,要求图片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() +" Height="+Height.ToString()+" 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("请选择图片文件!");    }   }

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.1235s