• 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 = "u4e0du5141u8bb8u7684u6587u4ef6u7c7bu578b";

                }

                //大小验证

                if (checkSize(size))

                {

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

                    state = "u6587u4ef6u5927u5c0fu8d85u51fau7f51u7ad9u9650u5236";

                }

                //保存图片

                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 = "u672au77e5u9519u8bef";

                URL = "";

            }

            return getUploadInfo();

        }

  • 相关阅读:
    Kali之Metasploit生成apk后门控制安卓
    迅雷后台上传?干掉迅雷后台进程和服务的一个批处理
    不用第三方软件–一键开关笔记本电脑wifi热点的批处理
    【PHP】创蓝253云通讯国际短信余额查询请求demo
    【PHP】创蓝253云通讯平台国际短信API接口demo
    创蓝253云通讯平台---短信验证码接口说明
    C++调取国际短信验证码----创蓝253云通讯平台---demo
    手机空号、停机、注销,空号检测为你去除无效号码
    上市公司都被撸垮,羊毛党就真的没有办法解决了吗?
    如何用Ruby调取创蓝253短信验证码
  • 原文地址:https://www.cnblogs.com/qingzhibin/p/4182735.html
Copyright © 2020-2023  润新知