码迷,mamicode.com
首页 > Web开发 > 详细

fileupload上传图片

时间:2019-11-06 10:29:59      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:open   replace   ppa   server   created   http   显示   上传图片   name   

 <asp:FileUpload ID="FileUpload1" runat="server"  accept="image/*" />

  

技术图片
          HttpFileCollection upFiles = Request.Files;
            if (upFiles.Count > 0 && upFiles.Count < 2)
            {
                string wenjianjia = "a_" + DateTime.Now.ToString("yyyy-MM-dd");
                string savePath = "/plugins/dangxingtijian/PC/face/img/" + wenjianjia;
                string savePaths = MapPath(savePath);
                if (!Directory.Exists(savePaths))
                {
                    Directory.CreateDirectory(savePaths);
                }

                for (int i = 0; i < upFiles.Count; i++)
                {
                    string url_a = "a" + DateTime.Now.Ticks.ToString() + i;
                    string url_f = "f" + DateTime.Now.Ticks.ToString() + i;

                    string extendName = string.Empty;
                    HttpPostedFile PostedFile = upFiles[i];
                    if (PostedFile.ContentLength > 0)
                    {
                        extendName = Path.GetExtension(PostedFile.FileName.ToLower()).Replace(".", "");
                        //保存 原始图
                        url_a = "/" + url_a + "." + extendName;
                        url_f = "/" + url_f + "." + extendName;
                        string url_as = savePaths + url_a;
                        string url_fs = savePaths + url_f;
                        //苹果手机 图片角度 调整
                        string url = savePaths + url_f;
                        PostedFile.SaveAs(url);
                        RemoveRotateFlips(url, url_as);
                        File.Delete(url);
                        //缩略图
                        MakeThumbnail(url_as, url_fs, 300, 400, "HW");
                        File.Delete(url_as);
                        //显示 图片
                        img_face.ImageUrl = savePath + url_f;
                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
上传方法

 

fileupload上传图片

标签:open   replace   ppa   server   created   http   显示   上传图片   name   

原文地址:https://www.cnblogs.com/nbsp12138/p/11803497.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!