using System; using System.Web; using System.IO; using System.Collections; using System.Linq; using System.Web.SessionState; namespace Mtxfw.shop { public class fileUp : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { if (context.Session["MemberIdMemberId"] != null || (context.Session["MemberId"] != null && context.Session["MemberName"] != null)) { context.Response.ContentType = "text/plain"; //上传配置 String pathbase = "Files/file/"; //保存路径 string[] filetype = { ".rar", ".doc", ".docx", ".zip", ".pdf", ".txt", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".mov", ".wmv", ".mp4", ".webm", ".flv" }; //文件允许格式 int size = 100; //文件大小限制,单位MB,同时在web.config里配置环境默认为100MB //上传文件 Hashtable info = new Hashtable(); Mtxfw.shop.Uploader up = new Mtxfw.shop.Uploader(); info = up.upFile(context, pathbase, filetype, size, (context.Session["MemberIdMemberId"] != null ? 1 : 0)); //获取上传状态 context.Response.Write("{'state':'" + info["state"] + "','url':'" + info["url"] + "','fileType':'" + info["currentType"] + "','original':'" + info["originalName"] + "'}"); //向浏览器返回数据json数据 } else { context.Response.Write("{'state':'0000000','url':'','fileType':'','original':''}"); //向浏览器返回数据json数据 } } public bool IsReusable { get { return false; } } } }