上传图片,要求图片200100象素,大小小于2M
作者:網(wǎng)際浪子專欄(曾用名littlehb)? http://blog.csdn.net/littlehb/
上傳圖片,要求圖片200100象素,大小小于2M,
如果圖片不符合要求,不能上傳,否則上傳圖片,上傳以后對(duì)圖片按系統(tǒng)日期動(dòng)態(tài)命名,保留路徑到數(shù)據(jù)庫(kù)里。
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("請(qǐng)選擇圖片文件!");
???}
??}
總結(jié)
以上是生活随笔為你收集整理的上传图片,要求图片200100象素,大小小于2M的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。