5

新手,求帮忙修改代码

把下面的一般处理程序改为控制器代码,且功能不变

public class uptupian : IHttpHandler,IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        HttpFileCollection files = context.Request.Files;

        yey_oa_dbEntities entity = new yey_oa_dbEntities();

        string spname = context.Request["spname"];
        string lurudate = context.Request["lurudate"];
        if (files.Count > 0)
        {
            for (int i = 0; i < files.Count; i++)
            {
                HttpPostedFile file = files[i];

                if (file.ContentLength > 0 && file.ContentLength < 1000 * 1024)
                {
                    //全路径  
                    string FullFullName = file.FileName;
                    //获取图片的名称   
                    string name = context.Request["cunpath1"];

                    string[] pa = name.Split('.');
                    int l = pa.Length;
                    string p = pa[l - 1];
                    string timeStamp = DateTime.Now.ToFileTime().ToString();
                    String fileName = timeStamp + "." + p;

                    string path = "~/Core/02WeiXinYinXiao/PhotoGuanli/RollPicture/gundongANDlogoIMG";
                    file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path) + "\\" + fileName);

                    context.Response.Write(fileName);
                }
                else
                {
                    context.Response.Write("noup");
                }
            }
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
查看全部
zeenTo
zeenTo
2015/08/04 05:27
  • 修改代码
  • 点赞
  • 收藏
  • 回答
    私信

3个回复