ueditor图片上传

net文件夹》imageUp.ashx

 

 

public void ProcessRequest(HttpContext context)

    {

 

        context.Response.ContentType = "text/plain";

        //上传配置

        int size = 2;           //文件大小限制,单位MB                             //文件大小限制,单位MB

        string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };         //文件允许格式

        //上传图片

        Hashtable info = new Hashtable();

        Uploader up = new Uploader();

        string path = ConfigurationManager.AppSettings["ImagePath"];   //上传服务器路径  

        info = up.upFile(context, path, filetype, size);                   //获取上传状态

        string title = up.getOtherInfo(context, "pictitle");                   //获取图片描述

        string oriName = up.getOtherInfo(context, "fileName");                //获取原始文件名

        HttpContext.Current.Response.Write("{‘url‘:‘" + info["url"] + "‘,‘title‘:‘" + title + "‘,‘original‘:‘" + oriName + "‘,‘state‘:‘" + info["state"] + "‘}");  //向浏览器返回数据json数据

    }

 net文件夹》Uploader.cs

public  Hashtable upFile(HttpContext cxt, string pathbase, string[] filetype, int size)

    {

        pathbase = GetFileName(pathbase);//服务器放置的图片文件夹

        string _filename = pathbase.Substring(pathbase.LastIndexOf("\\") + 1);

        pathbase = pathbase + "/";

        uploadpath = pathbase;

        try

        {

            uploadFile = cxt.Request.Files[0];

            originalName = uploadFile.FileName;

            //目录创建

            createFolder();

            //格式验证

            if (checkType(filetype))

            {

                //不允许的文件类型

                state = "\u4e0d\u5141\u8bb8\u7684\u6587\u4ef6\u7c7b\u578b";

            }

            //大小验证

            if (checkSize(size))

            {

                //文件大小超出网站限制

                state = "\u6587\u4ef6\u5927\u5c0f\u8d85\u51fa\u7f51\u7ad9\u9650\u5236";

            }

            //保存图片

            if (state == "SUCCESS")

            {

                filename = NameFormater.Format(cxt.Request["fileNameFormat"], originalName);

                var testname = filename;

                var ai = 1;

                while (File.Exists(uploadpath + testname))

                {

                    testname =  Path.GetFileNameWithoutExtension(filename) + "_" + ai++ + Path.GetExtension(filename);

                }

                uploadFile.SaveAs(uploadpath + testname);

                string path = ConfigurationManager.AppSettings["WebImagePath"];

                URL = path+_filename+"/" + testname;//文本域图片路径

            }

        }

        catch (Exception)

        {

            // 未知错误

            state = "\u672a\u77e5\u9519\u8bef";

            URL = "";

        }

        return getUploadInfo();

    }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。