为ckeditor编辑器加上传图片的功能
发布时间:2022-08-11 22:17:50
CKEditor官方演示是有上传图片和浏览服务器文件功能的,但是我们自己下载回来的却没有这两个功能…… 其实还需要下载另外一个组件:CKFinder,用它配合CKEditor来实现上传功能。 官方提供了PHP,Asp.Net和Asp三个语言版本的CKFinder,下载地址:http://ckfinder.com/download
将CKFinder解压缩到网站目录。调用方法如下(假设CKFinder在网站根目录,可以使用相对路径): CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl : '/ckfinder/ckfinder.html', filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?Type=Images', filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?Type=Flash', filebrowserUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files', filebrowserImageUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', filebrowserFlashUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' });
同时默认情况下是禁止上传的,还需要打开CKFinder目录下的config.php,将第32行的return false;修改为return true; 这里就是上传权限的认证了,你可以注意到上面有一大段英文注释,意思是不要简单的将它修改为return true,而是加上例如session验证等等,否则会很危险……
下面是官方文档,关于如何增加文件上传功能,给英文好的同学参考,上面说的方法其实就是下文中的Example 5:
Basic Configuration The filebrowserBrowseUrl setting is the location of an external file browser, that should be launched when "Browse Server" button(1) is pressed. The filebrowserUploadUrl setting is the location of a script that handles file uploads. If set, the "Upload" tab(2) will appear in dialog boxes (only where such functionality is available, i.e. in "Link", "Image" and "Flash" dialog windows). Example 1 CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl : '/browser/browse.php', filebrowserUploadUrl : '/uploader/upload.php', }); It is also possible to set a separate url for a selected dialog box, using the dialog name in file browser settings: filebrowser[dialogName]BrowseUrl and filebrowser[dialogName]UploadUrl. For example to set a special upload url for the image dialog, set the filebrowserImageUploadUrl property: Example 2 CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl : '/browser/browse.php', filebrowserImageBrowseUrl : '/browser/browse.php?type=Images' filebrowserUploadUrl : '/uploader/upload.php', filebrowserImageUploadUrl : '/uploader/upload.php?type=Images' }); In the example above, filebrowserBrowseUrl and filebrowserUploadUrl settings will be used by default, however in the Image dialog box, CKEditor will use filebrowserImageBrowseUrl and filebrowserImageUploadUrl configuration settings instead. File Browser Window Size The default width of file browser window in CKEditor is set to 80% of screen width, the default hight is set to 70% of screen height. If for some reasons, the default values are not suitable for you, you can change it to any other value. Use filebrowserWindowWidth to change width and filebrowserWindowHeight to change height of the window. To set the size of the window in pixels, just set the number value (e.g. "800"). If you prefer to set height and width of the window in percentage of the screen, remember to add percent sign at the end (e.g. "60%"). Example 3 CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl : '/browser/browse.php', filebrowserUploadUrl : '/uploader/upload.php', filebrowserWindowWidth : '640', filebrowserWindowHeight : '480', }); To set the window size of file browser inside of a specific dialog box, use filebrowser[dialogName]WindowWidth and filebrowser[dialogName]WindowHeight settings. For example, to change the file browser window size only in "Image" dialog box, change set the filebrowserImageWindowWidth and filebrowserImageWindowHeight settings. Example 4 CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl : '/browser/browse.php', filebrowserUploadUrl : '/uploader/upload.php', filebrowserImageWindowWidth : '640', filebrowserImageWindowHeight : '480', }); Using CKFinder CKFinder may be easily integrated with CKEditor (see live demo). The integration may be done in two ways: by setting CKEditor configuration options (example below) or using the CKFinder.SetupCKEditor() method available in CKFinder API. Example 5 CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl : '/ckfinder/ckfinder.html', filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?Type=Images', filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?Type=Flash', filebrowserUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files', filebrowserImageUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', filebrowserFlashUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' }); The example above is valid for PHP environment. /ckfinder/ is a base path to the CKFinder installation directory. If your using CKFinder for ASP, ASP.NET or ColdFusion remember to change "php" to the right extension: asp - CKFinder for ASP aspx - CKFinder for ASP.NET cfm - CKFinder for ColdFusion php - CKFinder for PHP Example 6 CKEditor + CKFinder integration with the use of CKFinder.SetupCKEditor() function: var editor = CKEDITOR.replace( 'editor1' ); CKFinder.SetupCKEditor( editor, '/ckfinder/' ); The second parameter of the SetupCKEditor() method is the path to the CKFinder installation. Please check the _samples/js/ckeditor.html sample distributed with CKFinder to see the full working example of this integration method.


猜你喜欢
- 这篇文章主要介绍了python框架django项目部署相关知识详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价
- 1、简介 table_cache是一个非常重要的MySQL性能参数,它在5.1.3之后的版本中叫做table_open_cache。tabl
- 因为固体物理书上的球面投影图太难看,就自学 javascipt 用 echarts 做了个可交互的,效果如下:上面为立方晶系主要晶面(晶向)
- 前言最近在试着研究飞浆平台的许多功能,看到了许多有意思的功能。其中可以将照片美化以及年龄调整这个功能让我想到了之前抖音的一个功能,所以特别感
- 绘制直线图,确定x范围和y的范围代码:import matplotlib.pyplot as pltimport numpy as npxp
- 解决方案1: 调用windows 的shell,但会有安全问题. * browseFolder.js * 该文件定义了BrowseFolde
- 一 计算公式:二 实现代码(1)import mathfrom tqdm import tqdmimport timetotal,s,n,t
- 全文索引在 MySQL 中是一个 FULLTEXT 类型索引。FULLTEXT 索引用于 MyISAM 表,可以在 CREATE TABLE
- 本文实例讲述了原生js实现的贪吃蛇网页版游戏。分享给大家供大家参考。具体实现方法如下:<html><head><
- 前言:Python中for循环和while循环本质上是没有区别的,但是在实际应用上,针对性不太一样。for循环,主要应用在遍历中,体现的是遍
- 第一种--对象键值去重Array.prototype.unique1 = function () { var r
- 如下所示:>>> import numpy as np>>> a = np.arange(12).res
- 本文为大家分享了mysql 5.7.17 winx64解压版安装配置方法,供大家参考,具体内容如下一、下载下载地址二、配置1. 解压下载的m
- 本文实例讲述了Python实现分割文件及合并文件的方法。分享给大家供大家参考。具体如下:分割文件split.py如下:#!/usr/bin/
- 前言在很早之前写过一篇怎么利用微博数据制作词云图片出来,之前的写得不完整,而且只能使用自己的数据,现在重新整理了一下,任何的微博数据都可以制
- 同时装配两个相同类型数据库1.配置文件:spring: profiles: active: devda
- <script language="javascript" src="js/sett
- 这也许是学习一门语言时大家都会问的一个问题,其实我个人认为无所谓哪个最好,关键在于哪个用着顺手,方便。还有很多人乐于去做排名,去看排名,哪个
- 1、什么是指令?指令通常以"v-"作为前缀, 以方便Vue知道你在使用一种特殊的标记。除了 Vue 核心携带着的一些默认
- 在自动化测试脚本的运行过程中,可以通过设置等待的方式来避免由于网络延迟或浏览器卡顿导致的偶然失败,常用的等待方式有三种:一、固定等待(tim