/** * Created by visual studio2010 * User: xuheng * Date: 12-3-7 * Time: 下午16:29 * To change this template use File | Settings | File Templates. */ using System; using System.Web; using System.IO; using System.Text.RegularExpressions; using System.Web.SessionState; namespace Mtxfw.VipSite { public class imageManager : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { Mtxfw.Utility.Config config = new Mtxfw.Utility.Config(""); if (context.Session["MemberId"] != null && context.Session["MemberName"] != null) { context.Response.ContentType = "text/plain"; string[] paths = {"Files/Image/"}; //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时 string[] filetype = config.webUpType.Split(','); //文件允许格式 string action = context.Server.HtmlEncode(context.Request["action"]); if (action == "get") { String str = String.Empty; foreach (string path in paths) { DirectoryInfo info = new DirectoryInfo(context.Server.MapPath("/" + path)); //目录验证 if (info.Exists) { foreach (FileInfo fi in info.GetFiles()) { if (Array.IndexOf(filetype, fi.Extension.Replace(".","")) != -1) { str += path + fi.Name + "ue_separate_ue"; } } DirectoryInfo[] infoArr = info.GetDirectories(); foreach (DirectoryInfo tmpInfo in infoArr) { if (config.webImgAllowSize.IndexOf(tmpInfo.Name) == -1) { foreach (FileInfo fi in tmpInfo.GetFiles()) { if (Array.IndexOf(filetype, fi.Extension.Replace(".", "")) != -1) { str += path + tmpInfo.Name + "/" + fi.Name + "ue_separate_ue"; } } } } } } context.Response.Write(str); } if (action == "del") { string[] delpics = context.Server.UrlDecode(context.Request["delpics"]).Split(','); foreach (string strpic in delpics) { string pic = strpic; if (pic != "") { bool b = true; foreach (string path in paths) { if (pic.IndexOf(path) != -1) { b = false; } else { pic = paths + pic; } } if (!b) { try { if (File.Exists(context.Server.MapPath(pic))) { File.Delete(context.Server.MapPath(pic)); } } catch (Exception err) { Mtxfw.Utility.Common.WriteHtml("/weixin/weixin.txt", err.ToString()); } } } } context.Response.Write("true"); } } } public bool IsReusable { get { return false; } } } }