首页 文章

在asp.net上为CKEditor启用图像上传

提问于
浏览
1

我使用CKEditor作为我的asp.net C#项目 . 如何为编辑器启用图像上载选项卡 . 我读了一些文章,但没有一篇文章有用 . 其中一些用于PHP . 我想要asp.net . 谢谢你的帮忙 .

3 回答

  • 1

    我喜欢使用filebrowserImageUploadUrl属性的http://www.codedigest.com/Articles/ASPNET/423_Upload_Images_and_Integrate_with_CKeditor_in_AspNet.aspx letutorial和我们自己的文件上传器实现 . 但上传的内容没有出现,也没有发生任何事情 . 我的代码在这里:

    <head runat="server">
    
        <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
        <script src="ckeditor/ckeditor.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                CKEDITOR.replace('<%=CKEditor1.ClientID %>', { filebrowserImageUploadUrl: '/Upload.ashx' });
            });
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <CKEditor:CKEditorControl ID="CKEditor1" BasePath="~/ckeditor/" runat="server" Width="600px" Height="200px"></CKEditor:CKEditorControl>
        </div>
        </form>
    </body>
    </html>
    

    和ashx文件:

    <%@ WebHandler Language="C#" Class="Upload" %>
    
    using System;
    using System.Web;
    
    public class Upload : IHttpHandler {
    
        public void ProcessRequest (HttpContext context) {
            HttpPostedFile uploads = context.Request.Files["upload"];
            string CKEditorFuncNum = context.Request["CKEditorFuncNum"];
            string file = System.IO.Path.GetFileName(uploads.FileName);
            uploads.SaveAs(context.Server.MapPath(".") + "\\Images\\" + file);
            string url = "/Images/" + file;
            context.Response.Write("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\");</script>");
            context.Response.End();            
        }
    
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    
  • 4

    如果您只想启用隐藏选项卡,则仅在脚本文件夹下添加

    CKEDITOR.config.extraPlugins = 'imageuploader';
    

    但是在控制台中会出现错误,因为您必须定义链接,这将是上传文件/图像的操作,例如

    filebrowserImageBrowseUrl: 'YourController/YourAction',            
    filebrowserImageUploadUrl: 'YourController/YourAction'
    
  • 0

    最后我找到了解决方案 .

    我做了两件事来解决我的问题 .

    首先我编辑了config.ascx文件并将基本URL设置为images文件夹 . 如下:

    public override void SetConfig(){

    // The base URL used to reach files in CKFinder through the browser.
        BaseUrl = "~/images/";
        // The phisical directory in the server where the file will end up. If
        // blank, CKFinder attempts to resolve BaseUrl.
        BaseDir = "";
    }
    

    我的错误是,我的页面是在管理员文件夹,我把ckeditor和ckfinder文件夹放在我网站的根目录下 .

    通过将这些文件放在admin文件夹中,问题就出现了问题 .

    谢谢 .

相关问题