日期:2014-05-18 浏览次数:20907 次
public string PicUpLoad() { string save_filePath = "/Image/nopic.gif"; if (this.fuPic.FileName != null && this.fuPic.HasFile) { string ImgName = this.fuPic.FileName; string ImgExtention = System.IO.Path.GetExtension(ImgName).ToLower(); int ImgSize = this.fuPic.PostedFile.ContentLength;//此处取得的文件大小的单位是byte if (ImgExtention == ".gif" || ImgExtention == ".jpg" || ImgExtention == ".jpeg") { if (ImgSize / 1024 < 1024)//转换为kb { string myTime; myTime = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString("000"); string pic_path = Server.MapPath("/Image/"); //上传文件夹 save_filePath = pic_path + myTime + ImgExtention; this.fuPic.SaveAs(save_filePath); //上传文件 save_filePath = "/Image/" + myTime + ImgExtention; } else { ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('图片大小不能超过1M!');</script>"); save_filePath = "0"; } } else { ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('图片格式不正确,只支持.gif/.jpg/.jpeg格式类型的图片!');</script>"); save_filePath = "0"; } } return save_filePath; }