码迷,mamicode.com
首页 > Web开发 > 详细

ueditor图片上传

时间:2014-12-24 17:39:54      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

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();

    }

 

ueditor图片上传

标签:

原文地址:http://www.cnblogs.com/qingzhibin/p/4182735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!