软测单独项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
2.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
namespace FangYar.WebUI.ashx
{
/// <summary>
/// FileUpHandler 的摘要说明
/// </summary>
public class FileUpHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "文件上传操作请求", "");
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
//上传配置
string pathbase = "../upload/"; //保存路径
int size = 10; //文件大小限制,单位mb //文件大小限制,单位KB
// string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" }; //文件允许格式
string callback = context.Request["callback"];
string editorId = context.Request["editorid"];
//上传图片
Hashtable info;
FangYar.Common.Uploader up = new FangYar.Common.Uploader();
info = up.upFile(context, pathbase,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) + "}";
}
}
}