<asp:FileUpload ID="uploaderInput" runat="server" multiple="multiple" accept="image/*"/> <asp:Button ID="but_imgup" runat="server" Text="照片上传" /> <asp:Image ID="img_face" runat="server" Width="30" Height="30" />
#region 上传方法 public bool Upload() { HttpFileCollection upFiles = Request.Files; if (upFiles.Count > 0) { string wenjianjia = "a_" + DateTime.Now.ToString("yyyy-MM-dd"); string savePath = "~/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, 350, 350, "H"); File.Delete(url_as); //显示 图片 img_face.ImageUrl = savePath + url_f; } } return true; } else { return false; } } #endregion