fileupload上传图片

天大地大妈咪最大 提交于 2019-12-03 16:55:49
 <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
上传方法

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!