20,359
社区成员
发帖
与我相关
我的任务
分享
public class upload : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
string err = string.Empty;
HttpPostedFile file = null;
try
{
file = context.Request.Files["upload"];
file.SaveAs(context.Server.MapPath("~/upload/" + file.FileName));
}
catch (Exception ex)
{
err = ex.Message;
}
System.Text.StringBuilder str = new System.Text.StringBuilder();
str.Append("{\"err\":\"");
str.Append(err);
str.Append("\",");
str.Append("\"msg\":\"");
string msg = err == string.Empty ? "upload/" + file.FileName : string.Empty;
str.Append(msg);
str.Append("\"");
str.Append("}");
context.Response.Write(str);
}