ASP页面怎样把图片添加到自己新建的文件夹里面?
展开全部
protected string FileUpload() { //先生成图片上传的物理位置文件夹 例如 20090821 \\ string UploadPicSubPhypath = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "\\"; string strPhyPath = ConfigurationManager.AppSettings["phccda_PhyPath"] + "UploadPic\\2009valuepizza\\" + UploadPicSubPhypath; try { //判断路径是否存在,不存在则创建 if (!System.IO.Directory.Exists(strPhyPath)) { System.IO.Directory.CreateDirectory(strPhyPath); } //获取文件 HttpPostedFile PostedFile = Request.Files[0]; string imgNameOnly = System.IO.Path.GetFileName(PostedFile.FileName); string imgNameNoExt = System.IO.Path.GetFileNameWithoutExtension(PostedFile.FileName); string imgExt = System.IO.Path.GetExtension(PostedFile.FileName).ToString().ToLower(); Random rdAvg = new Random(); int iAvg = rdAvg.Next(1, 10000); string strFileNameB = "thum_" + DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + iAvg.ToString() + ".jpg"; string strFileNameS = "thums_" + DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + iAvg.ToString() + ".jpg"; System.Drawing.Image oriImg = System.Drawing.Image.FromStream(PostedFile.InputStream); oriImg.Save(strPhyPath + strFileNameB, System.Drawing.Imaging.ImageFormat.Jpeg); System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); System.Drawing.Image myThumbnail = oriImg.GetThumbnailImage(160, 116, myCallback, IntPtr.Zero); myThumbnail.Save(strPhyPath + strFileNameS, System.Drawing.Imaging.ImageFormat.Jpeg); string pic_url = UploadPicSubPhypath.Replace("\\", "/") + strFileNameS; Session["picurl"] = pic_url; return "result=0"; } catch (Exception exp) { Response.Write(exp.Message); return "result=1"; } }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询