首次推送

This commit is contained in:
lym
2026-03-09 00:13:46 +08:00
commit b19613bb31
13974 changed files with 2767735 additions and 0 deletions

View File

@@ -0,0 +1,225 @@
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Collections;
namespace Mtxfw.VipSite
{
/// <summary>
/// UEditor编辑器通用上传类
/// </summary>
public class Uploader
{
string state = "SUCCESS";
string URL = null;
string currentType = null;
string uploadpath = null;
string filename = null;
string originalName = null;
HttpPostedFile uploadFile = null;
/**
* 上传文件的主处理方法
* @param HttpContext
* @param string
* @param string[]
*@param int
* @return Hashtable
*/
public Hashtable upFile(HttpContext cxt, string pathbase, string[] filetype, int size)
{
pathbase = pathbase + DateTime.Now.ToString("yyyy-MM-dd") + "/";
uploadpath = cxt.Server.MapPath(pathbase);//获取文件上传路径
try
{
uploadFile = cxt.Request.Files[0];
originalName = uploadFile.FileName;
//目录创建
createFolder();
//格式验证
if (checkType(filetype))
{
state = "不允许的文件类型";
}
//大小验证
if (checkSize(size))
{
state = "文件大小超出网站限制";
}
//保存图片
if (state == "SUCCESS")
{
filename = reName();
uploadFile.SaveAs(uploadpath + filename);
if (!Mtxfw.Utility.Common.IsAllowedExtension(uploadpath + filename))
{
//您的权限不足
state = "3\u60a8\u7684\u6743\u9650\u4e0d\u8db3";
File.Delete(uploadpath + filename);
}
else
{
URL = pathbase + filename;
}
}
}
catch (Exception err)
{
Mtxfw.Utility.Common.WriteHtml("/weixin/weixin.txt", err.ToString());
state = "未知错误";
URL = "";
}
return getUploadInfo();
}
/**
* 上传涂鸦的主处理方法
* @param HttpContext
* @param string
* @param string[]
*@param string
* @return Hashtable
*/
public Hashtable upScrawl(HttpContext cxt, string pathbase, string tmppath, string base64Data)
{
pathbase = pathbase + DateTime.Now.ToString("yyyy-MM-dd") + "/";
uploadpath = cxt.Server.MapPath(pathbase);//获取文件上传路径
FileStream fs = null;
try
{
//创建目录
createFolder();
//生成图片
filename = System.Guid.NewGuid() + ".png";
fs = File.Create(uploadpath + filename);
byte[] bytes = Convert.FromBase64String(base64Data);
fs.Write(bytes, 0, bytes.Length);
URL = pathbase + filename;
}
catch (Exception e)
{
state = "未知错误";
URL = "";
}
finally
{
fs.Close();
deleteFolder(cxt.Server.MapPath(tmppath));
}
return getUploadInfo();
}
/**
* 获取文件信息
* @param context
* @param string
* @return string
*/
public string getOtherInfo(HttpContext cxt, string field)
{
string info = null;
if (cxt.Request.Form[field] != null && !String.IsNullOrEmpty(cxt.Request.Form[field]))
{
info = field == "fileName" ? cxt.Request.Form[field].Split(',')[1] : cxt.Request.Form[field];
}
return info;
}
/**
* 获取上传信息
* @return Hashtable
*/
private Hashtable getUploadInfo()
{
Hashtable infoList = new Hashtable();
infoList.Add("state", state);
infoList.Add("url", URL);
infoList.Add("originalName", originalName);
infoList.Add("name", Path.GetFileName(URL));
infoList.Add("size", uploadFile.ContentLength);
infoList.Add("type", Path.GetExtension(originalName));
return infoList;
}
/**
* 重命名文件
* @return string
*/
private string reName()
{
return System.Guid.NewGuid() + getFileExt();
}
/**
* 文件类型检测
* @return bool
*/
private bool checkType(string[] filetype)
{
currentType = getFileExt();
string strfiletype = getFileExt0();
if (Array.IndexOf(filetype, currentType.Replace(".", "")) == -1)
{
return true;
}
else
{
return Array.IndexOf(filetype, strfiletype.Replace("image/", "")) == -1;
}
}
/**
* 文件大小检测
* @param int
* @return bool
*/
private bool checkSize(int size)
{
return uploadFile.ContentLength >= (size * 1024 * 1024);
}
/**
* 获取文件扩展名
* @return string
*/
private string getFileExt()
{
string[] temp = uploadFile.FileName.Split('.');
return "." + temp[temp.Length - 1].ToLower();
}
private string getFileExt0()
{
string strContentType = uploadFile.ContentType.ToLower();
return strContentType;
}
/**
* 按照日期自动创建存储文件夹
*/
private void createFolder()
{
if (!Directory.Exists(uploadpath))
{
Directory.CreateDirectory(uploadpath);
}
}
/**
* 删除存储文件夹
* @param string
*/
public void deleteFolder(string path)
{
//if (Directory.Exists(path))
//{
// Directory.Delete(path, true);
//}
}
}
}

View File

@@ -0,0 +1,46 @@
<%@ WebHandler Language="C#" Class="Mtxfw.VipSite.getContent" %>
/**
* Created by visual studio 2010
* User: xuheng
* Date: 12-3-6
* Time: 下午21:23
* To get the value of editor and output the value .
*/
using System;
using System.Web;
namespace Mtxfw.VipSite
{
public class getContent : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
//获取数据
string content = context.Request.Form["myEditor"];
//存入数据库或者其他操作
//-------------
//显示
context.Response.Write("<script src='../third-party/jquery.min.js'></script>");
context.Response.Write("<script src='../third-party/mathquill/mathquill.min.js'></script>");
context.Response.Write("<link rel='stylesheet' href='../third-party/mathquill/mathquill.css'/>");
context.Response.Write("<div class='content'>" + content + "</div>");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

View File

@@ -0,0 +1 @@
<%@ WebHandler Language="C#" CodeBehind="getRemoteImage.ashx.cs" Class="Mtxfw.VipSite.getRemoteImage" %>

View File

@@ -0,0 +1,135 @@
/**
* Created by visual studio 2010
* User: xuheng
* Date: 12-3-8
* Time: 下午13:33
* To get the Remote image.
*/
using System;
using System.Web;
using System.Collections;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Web.SessionState;
namespace Mtxfw.VipSite
{
public class getRemoteImage : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
if (context.Session["MemberId"] != null && context.Session["MemberName"] != null)
{
string savePath = "/Files/"; //保存文件地址
string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" }; //文件允许格式
int fileSize = 3000; //文件大小限制单位kb
string uri = context.Server.HtmlEncode(context.Request["upfile"]);
uri = uri.Replace("&amp;", "&");
string[] imgUrls = Regex.Split(uri, "ue_separate_ue", RegexOptions.IgnoreCase);
ArrayList tmpNames = new ArrayList();
WebClient wc = new WebClient();
HttpWebResponse res;
String filename = String.Empty;
String imgUrl = String.Empty;
String currentType = String.Empty;
try
{
for (int i = 0, len = imgUrls.Length; i < len; i++)
{
imgUrl = imgUrls[i];
if (imgUrl.Substring(0, 7) != "http")
{
tmpNames.Add("error!");
continue;
}
//格式验证
int temp = imgUrl.LastIndexOf('.');
currentType = imgUrl.Substring(temp).ToLower();
if (Array.IndexOf(filetype, currentType) == -1)
{
tmpNames.Add("error!");
continue;
}
res = (HttpWebResponse)WebRequest.Create(imgUrl).GetResponse();
//http检测
if (res.ResponseUri.Scheme.ToLower().Trim() != "http")
{
tmpNames.Add("error!");
continue;
}
//大小验证
if (res.ContentLength > fileSize * 1024)
{
tmpNames.Add("error!");
continue;
}
//死链验证
if (res.StatusCode != HttpStatusCode.OK)
{
tmpNames.Add("error!");
continue;
}
//检查mime类型
if (res.ContentType.IndexOf("image") == -1)
{
tmpNames.Add("error!");
continue;
}
res.Close();
var filepath = savePath + DateTime.Now.ToString("yyyy-MM-dd") + "/";
//创建保存位置
if (!Directory.Exists(context.Server.MapPath(filepath)))
{
Directory.CreateDirectory(context.Server.MapPath(filepath));
}
//写入文件
filename = filepath + System.Guid.NewGuid() + currentType;
wc.DownloadFile(imgUrl, context.Server.MapPath(filename));
tmpNames.Add(filename);
}
}
catch (Exception)
{
tmpNames.Add("error!");
}
finally
{
wc.Dispose();
}
context.Response.Write("{url:'" + converToString(tmpNames) + "',tip:'远程图片抓取成功!',srcUrl:'" + uri + "'}");
}
}
//集合转换字符串
private string converToString(ArrayList tmpNames)
{
String str = String.Empty;
for (int i = 0, len = tmpNames.Count; i < len; i++)
{
str += tmpNames[i] + "ue_separate_ue";
if (i == tmpNames.Count - 1)
str += tmpNames[i];
}
return str;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

View File

@@ -0,0 +1 @@
<%@ WebHandler Language="C#" CodeBehind="imageManager.ashx.cs" Class="Mtxfw.VipSite.imageManager" %>

View File

@@ -0,0 +1,118 @@
/**
* 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;
}
}
}
}

View File

@@ -0,0 +1,65 @@
<%@ WebHandler Language="C#" Class="Mtxfw.VipSite.imageUp" %>
using System;
using System.Web;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Web.SessionState;
namespace Mtxfw.VipSite
{
public class imageUp : IHttpHandler, IRequiresSessionState
{
public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config("");
public void ProcessRequest(HttpContext context)
{
if (context.Session["MemberId"] != null && context.Session["MemberName"] != null)
{
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
//上传配置
string pathbase = "/Files/Image/"; //保存路径
int size = 10; //文件大小限制,单位mb //文件大小限制单位KB
string[] filetype = config.webUpType.Split(','); //文件允许格式
string callback = context.Request["callback"];
string editorId = context.Request["editorid"];
//上传图片
Hashtable info;
Uploader up = new Uploader();
info = up.upFile(context, pathbase, filetype, size); //获取上传状态
string json = BuildJson(info);
context.Response.ContentType = "text/html";
if (callback != null)
{
context.Response.Write(String.Format("<script>{0}(JSON.parse(\"{1}\"));</script>", callback, json));
}
else
{
context.Response.Write(json);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
private string BuildJson(Hashtable info)
{
List<string> fields = new List<string>();
string[] keys = new string[] { "originalName", "name", "url", "size", "state", "type" };
for (int i = 0; i < keys.Length; i++)
{
fields.Add(String.Format("\"{0}\": \"{1}\"", keys[i], info[keys[i]]));
}
return "{" + String.Join(",", fields) + "}";
}
}
}