<%@ Import Namespace="XGHUNLIAN.Common" %>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO;
namespace XGHUNLIAN.tools { ///
public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string shipin = "\*.avi \*.rmvb \*.rm \*.asf \*.divx \*.mpg \*.mpeg \*.mpe \*.wmv \*.mp4 \*.mkv \*.vob"; string allowExtension =string.Join("|",new string \[\]{ ".jpg", ".jpeg", ".gif", ".bmp", ".png", ".JPG", ".JPEG", ".GIF", ".BMP", ".PNG" }); if (context.Request.Files.Count > ) { for (int i = ; i < context.Request.Files.Count; i++) { HttpPostedFile filePost = context.Request.Files\[i\]; // 获取上传的文件 string aFile = filePost.FileName; string aLastName = aFile.Substring(aFile.LastIndexOf(".") + , (aFile.Length - aFile.LastIndexOf(".") - )); //扩展名 if (shipin.IndexOf(aLastName) == - && allowExtension.IndexOf(aLastName) == -) { context.Response.Write("{\\"code\\":\\"1\\",\\"data\\":\\"\\"}"); context.Response.End(); } string filename = ""; string filePath = SaveExcelFile(filePost,ref filename); // 保存文件并获取文件路径 BLL.wei\_Member bll = new BLL.wei\_Member(); if (bll.AddImgUrl(context.Request.QueryString\["openid"\], filename)) { context.Response.Write("{\\"code\\":\\"0\\",\\"data\\":\\"" + filename + "\\"}"); context.Response.End(); } context.Response.Write("{\\"code\\":\\"1\\",\\"data\\":\\"\\"}"); context.Response.End(); } } } public bool IsReusable { get { return false; } } public string SaveExcelFile(HttpPostedFile file,ref string filename\_) { try { var fileName = file.FileName.Insert(file.FileName.LastIndexOf('.'), "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff")); var filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Upload/Image"), fileName); string directoryName = Path.GetDirectoryName(filePath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } file.SaveAs(filePath); filename\_ = fileName; return filePath; } catch { return string.Empty; } } } 复制
public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string shipin = "\*.avi \*.rmvb \*.rm \*.asf \*.divx \*.mpg \*.mpeg \*.mpe \*.wmv \*.mp4 \*.mkv \*.vob"; string allowExtension =string.Join("|",new string \[\]{ ".jpg", ".jpeg", ".gif", ".bmp", ".png", ".JPG", ".JPEG", ".GIF", ".BMP", ".PNG" }); if (context.Request.Files.Count > ) { for (int i = ; i < context.Request.Files.Count; i++) { HttpPostedFile filePost = context.Request.Files\[i\]; // 获取上传的文件 string aFile = filePost.FileName; string aLastName = aFile.Substring(aFile.LastIndexOf(".") + , (aFile.Length - aFile.LastIndexOf(".") - )); //扩展名 if (shipin.IndexOf(aLastName) == - && allowExtension.IndexOf(aLastName) == -) { context.Response.Write("{\\"code\\":\\"1\\",\\"data\\":\\"\\"}"); context.Response.End(); } string filename = ""; string filePath = SaveExcelFile(filePost,ref filename); // 保存文件并获取文件路径 BLL.wei\_Member bll = new BLL.wei\_Member(); if (bll.AddImgUrl(context.Request.QueryString\["openid"\], filename)) { context.Response.Write("{\\"code\\":\\"0\\",\\"data\\":\\"" + filename + "\\"}"); context.Response.End(); } context.Response.Write("{\\"code\\":\\"1\\",\\"data\\":\\"\\"}"); context.Response.End(); } } } public bool IsReusable { get { return false; } } public string SaveExcelFile(HttpPostedFile file,ref string filename\_) { try { var fileName = file.FileName.Insert(file.FileName.LastIndexOf('.'), "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff")); var filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Upload/Image"), fileName); string directoryName = Path.GetDirectoryName(filePath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } file.SaveAs(filePath); filename\_ = fileName; return filePath; } catch { return string.Empty; } } }
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章