经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » PHP » 查看文章
php版本CKEditor 4和CKFinder安装及配置方法图文教程
来源:jb51  时间:2019/6/6 8:32:40  对本文有异议

本文实例讲述了php版本CKEditor 4和CKFinder安装及配置方法。分享给大家供大家参考,具体如下:

下载并解压CKEditor 4和CKFinder

CKEditor 4下载地址:https://ckeditor.com/cke4/builder,选择自定义的版本,记得加上中文语言包

CKFinder下载地址:https://download.cksource.com/CKFinder/CKFinder%20for%20PHP/3.4.4/ckfinder_php_3.4.4.zip

查看CKEditor的示例文件,http://127.0.0.1/ckeditor/samples/

根据你的需求选择自定义工具栏,选好之后点击Get toolbar config,把这个配置代码复制,备用

在CKEditor 4同级目录新建index.html,和myconfig.js

index.html的源代码为:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CKEditor Sample</title>
  6. <!-- 加载ckeditor.js -->
  7. <script src="./ckeditor/ckeditor.js"></script>
  8. </head>
  9. <body id="main">
  10. <textarea name="editor1" id="editor1" cols="30" rows="10">
  11. 这是一个CKEditor测试
  12. </textarea>
  13. <script>
  14. // 这样就可以使用啦
  15. CKEDITOR.replace('editor1',{
  16. //toolbar : 'Basic', //方式1,在此直接写配置
  17. //uiColor : '#9ab8f5'
  18. customConfig : '../myconfig.js' //方式2,加载配置js,相对于ckeditor.js的路径
  19. });
  20. </script>
  21. </body>
  22. </html>
  23.  

myconfig.js的源代码为:

  1. //特别注意,每次修改都要ctrl+f5 清除缓存后查看
  2. CKEDITOR.editorConfig = function( config ) {
  3. config.language = "zh-cn" ; //语言,对应ckeditor下的lang文件夹
  4. config.uiColor = '#9ab8f5'; //编辑器颜色
  5. config.width = '900'; //编辑器宽
  6. config.height = '500'; //编辑器高
  7. //自定义工具栏,刚才从示例哪里复制的代码
  8. config.toolbarGroups = [
  9. '/',
  10. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  11. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  12. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  13. { name: 'forms', groups: [ 'forms' ] },
  14. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  15. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  16. { name: 'links', groups: [ 'links' ] },
  17. { name: 'insert', groups: [ 'insert' ] },
  18. { name: 'styles', groups: [ 'styles' ] },
  19. { name: 'colors', groups: [ 'colors' ] },
  20. { name: 'tools', groups: [ 'tools' ] },
  21. { name: 'others', groups: [ 'others' ] },
  22. { name: 'about', groups: [ 'about' ] }
  23. ];
  24. config.removeButtons = 'NewPage,Save,Preview,Cut,Copy,Paste,PasteText,PasteFromWord,Find,Replace,SelectAll,Scayt,HiddenField,Form,Radio,TextField,Textarea,Select,Button,ImageButton,Outdent,Indent,Subscript,Superscript,Strike,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Anchor,Table,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,ShowBlocks,About,Source';
  25. //ckfinder的相关配置项
  26. config.filebrowserBrowseUrl = './ckfinder/ckfinder.html' ;
  27. config.filebrowserImageBrowseUrl = './ckfinder/ckfinder.html?type=Images' ;
  28. config.filebrowserFlashBrowseUrl = './ckfinder/ckfinder.html?type=Flash' ;
  29. config.filebrowserUploadUrl = './ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files' ;
  30. config.filebrowserImageUploadUrl = './ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images' ;
  31. config.filebrowserFlashUploadUrl = './ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' ;
  32. config.filebrowserWindowWidth = '600'; //文件浏览宽
  33. config.filebrowserWindowHeight = '300'; //文件浏览宽
  34. };
  35.  

网上搜索有同学总结了最全的配置项,详见附录说明

图片上传,点击浏览服务器,会出下面的提示

修改ckfinder文件夹下config.php,将29行的return false;改为return true;

ckfinder即可正常使用,上传图片的默认保存位置为根目录下的ckfinder->userfiles->images

附:CKEditor基本配置示例

  1. CKEDITOR.editorConfig = function( config )
  2. {
  3. // config.language = 'fr';
  4. // config.uiColor = '#AADC6E';
  5. config.filebrowserBrowseUrl = '/CKEditorAndCKFinder/ckfinder/ckfinder.html' ;
  6. config.filebrowserImageBrowseUrl = '/CKEditorAndCKFinder/ckfinder/ckfinder.html?type=Images' ;
  7. config.filebrowserFlashBrowseUrl = '/CKEditorAndCKFinder/ckfinder/ckfinder.html?type=Flash' ;
  8. config.filebrowserUploadUrl = '/CKEditorAndCKFinder/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Files' ;
  9. config.filebrowserImageUploadUrl = '/CKEditorAndCKFinder/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Images' ;
  10. config.filebrowserFlashUploadUrl = '/CKEditorAndCKFinder/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Flash' ;
  11. config.filebrowserWindowWidth = '1000';
  12. config.filebrowserWindowHeight = '700';
  13. config.language = "zh-cn" ;
  14. //编辑器样式,有三种:'kama'(默认)、'office2003'、'v2'
  15. //config.skin = "v2";
  16. //背景颜色
  17. //config.uiColor = "#FFF";
  18. //工具栏(基础'Basic'、全能'Full'、自定义)
  19. config.toolbar = 'Full';
  20. //工具栏是否可以被收缩
  21. //config.toolbarCanCollapse = false;
  22. //工具栏的位置
  23. //config.toolbarLocation = "bottom";
  24. //工具栏默认是否展开
  25. //config.toolbarStartupExpanded = false;
  26. //取消“拖拽以改变尺寸”的功能
  27. //config.resize_enabled = false;
  28. //改变大小的最大高度
  29. //config.resize_maxHeight = 3000;
  30. //改变大小的最大宽度
  31. //config.resize_minWidth = 3000;
  32. //改变大小的最小高度
  33. //config.resize_minHeight = 250;
  34. //改变大小的最小宽度
  35. //config.resize_minWidth = 750;
  36. //当提交包含有此编辑器的表单时,是否自动更新元素内的数据
  37. //config.autoUpdateElement = true;
  38. //设置是使用绝对目录还是相对目录,为空为相对目录
  39. //config.baseHref = "";
  40. //编辑器的z-index值
  41. //config.baseFloatZIndex = 10000;
  42. //设置快捷键
  43. //config.keystrokes = [];
  44. //设置快捷键 可能与浏览器快捷键冲突
  45. //config.blockedKeystrokes = [];
  46. //设置编辑内元素的背景色的取值
  47. //config.colorButton_backStyle = {
  48. // element : 'span',
  49. // styles : {'background-color' : '#(color)'}
  50. //}
  51. //设置前景色的取值
  52. //config.colorButton_colors
  53. //是否在选择颜色时显示“其它颜色”选项
  54. //config.colorButton_enableMore = false;
  55. //前景色默认值设置
  56. //config.colorButton_foreStyle = {
  57. // element : 'span',
  58. // styles : {'background-color' : '#(color)'}
  59. //}
  60. //所需要添加的CSS文件 在此添加 可使用相对路径和网站的绝对路径
  61. //config.contentsCss = "ckeditor/contents.css"
  62. //文字方向
  63. //config.contentsLangDirection = "rtl";
  64. //CKeditor的配置文件 若不想配置 留空即可
  65. //CKEDITOR.replace("myfield",{customConfig : "ckeditor/config.js"});
  66. //界面编辑框的背景色
  67. //config.dialog_backgroundCoverColor = "rgb(a,b,c)";
  68. //config.dialog_backgroundCoverColor = "white";
  69. //背景的不透明度
  70. //config.dialog_backgroundCoverOpacity = 0.5;
  71. //移动或者改变元素时 边框的吸附距离 单位:像素
  72. //config.dialog_magnetDistance = 20;
  73. //是否拒绝本地拼写检查和提示 默认为拒绝 目前仅firefox和safari支持
  74. //config.disableNativeSpellChecker = true;
  75. //进行表格编辑功能 如:添加行或列 目前仅firefox支持
  76. //sconfig.disableNativeTableHandles = true; 默认不开启
  77. //设置HTML文档类型
  78. //config.docType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
  79. //是否对编辑区域进行渲染
  80. //config.editingBlock = true;
  81. //编辑器中回车产生的标签
  82. //config.enterMode = CKEDITOR_ENTER_BR;
  83. //是否使用HTML实体进行输出
  84. //config.entities = true;
  85. //定义更多的实体
  86. //config.entities_additional = "#1049";
  87. //是否转换一些难以显示的字符为相应的HTML字符
  88. //config.entities_greek = true;
  89. //是否转换一些拉丁字符为HTML
  90. //cofig.entities_latin = true;
  91. //是否转换一些特殊字符为ASCII字符
  92. //config.entities_processNumerical = false;
  93. //添加新组件
  94. //config.extraPlugins = "myplugin";
  95. //使用搜索时的高亮色
  96. //config.find_highlight = {
  97. // element : "span",
  98. // style : {"background-color" : "#ff0", "color" : "#00f"}
  99. //}
  100. //默认的字体名
  101. //config.font_defaultLabel = "Arial";
  102. //字体编辑时的字符集 可以添加常用的中文字符:宋体、楷体、黑体等
  103. //config.font_names = "Arial;Times New Roman;Verdana";
  104. //文字的默认式样
  105. //config.font_style = {};
  106. //字体默认大小
  107. //config.fontSize_defaultLabel = "12px";
  108. //字体编辑时可选的字体大小
  109. //config.fontSize_sizes = "8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px";
  110. //设置字体大小时 使用的式样
  111. //config.fontSize_style = {};
  112. //是否强制复制来的内容去除格式
  113. //config.forcePasteAsPlainText = false;//不去除
  114. //是否强制用“&”来代替“&”
  115. //config.forceSimpleAmpersand = false;
  116. //对address标签进行格式化
  117. //config.format_address = { element : 'address', attributes : { class : 'styledAddress' } };
  118. //对DIV标签自动进行格式化
  119. //config.format_div = { element : 'div', attributes : { class : 'normalDiv' } };
  120. //对H1标签自动进行格式化
  121. //config.format_h1 = { element : 'h1', attributes : { class : 'contentTitle1' } };
  122. //对H2标签自动进行格式化
  123. //config.format_h2 = { element : 'h2', attributes : { class : 'contentTitle2' } };
  124. //对H3标签自动进行格式化
  125. //config.format_h3 = { element : 'h3', attributes : { class : 'contentTitle3' } };
  126. //对H4标签自动进行格式化
  127. //config.format_h4 = { element : 'h4', attributes : { class : 'contentTitle4' } };
  128. //对H5标签自动进行格式化
  129. //config.format_h5 = { element : 'h5', attributes : { class : 'contentTitle5' } };
  130. //对H6标签自动进行格式化
  131. //config.format_h6 = { element : 'h6', attributes : { class : 'contentTitle6' } };
  132. //对P标签自动进行格式化
  133. //config.format_p = { element : 'p', attributes : { class : 'normalPara' } };
  134. //对PRE标签自动进行格式化
  135. //config.format_pre = { element : 'pre', attributes : { class : 'code' } };
  136. //用分号分隔的标签名字 在工具栏上显示
  137. //config.format_tags = "p;h1;h2;h3;h4;h5;h6;pre;address;div";
  138. //是否使用完整的html编辑模式 如使用,其源码将包含:<html><body></body></html>等标签
  139. //config.fullPage = false;
  140. //是否忽略段落中的空字符
  141. //config.ignoreEmptyParagraph = true;
  142. //在清除图片属性框中的链接属性时 是否同时清除两边的<a>标签
  143. //config.image_removeLinkByEmptyURL = true;
  144. //一组用逗号分隔的标签名称,显示在左下角的层次嵌套中
  145. //config.menu_groups ='clipboard,form,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,flash,checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea';
  146. //显示子菜单时的延迟,单位:ms
  147. //config.menu_subMenuDelay = 400;
  148. //当执行“新建”命令时,编辑器中的内容
  149. //config.newpage_html = "";
  150. //当从word里复制文字进来时,是否进行文字的格式化去除
  151. //config.pasteFromWorldIgnoreFontFace = true; //默认忽略格式
  152. //是否使用<h1><h2>等标签修饰或者代替从word文档中粘贴过来的内容
  153. //config.pasteFromWorkKeepsStructure = false;
  154. //从word中粘贴内容时是否移除格式
  155. //config.pasteFromWorkRemoveStyle = false;
  156. //对应后台语言的类型来对输出的HTML内容进行格式化,默认为空
  157. //config.protectedSource.push( /<\?[\s\S]*?\?>/g ); // PHP code
  158. //config.protectedSource.push( /<%[\s\S]*?%>/g ); // ASP code
  159. //config.protectedSource.push( /(]+>[\s|\S]*?<\/asp:[^\>]+>)|(]+\/>)/gi ); // ASP.Net code
  160. //当输入:shift+Enter时插入的标签
  161. //config.shiftEnterMode = CKEDITOR.ENTER_P;
  162. //可选的表情替代字符
  163. //config.smiley_descriptions = [
  164. // ':)', ':(', ';)', ':D', ':/', ':P',
  165. // '', '', '', '', '', '',
  166. // '', ';(', '', '', '', '',
  167. // '', ':kiss', '' ];
  168. //对应的表情图片
  169. //config.smiley_images = [
  170. // 'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','confused_smile.gif','tounge_smile.gif',
  171. // 'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angry_smile.gif','angel_smile.gif','shades_smile.gif',
  172. // 'devil_smile.gif','cry_smile.gif','lightbulb.gif','thumbs_down.gif','thumbs_up.gif','heart.gif',
  173. // 'broken_heart.gif','kiss.gif','envelope.gif'];
  174. //表情的地址
  175. //config.smiley_path = "plugins/smiley/images";
  176. //页面载入时,编辑框是否立即获得焦点
  177. //config.startupForce = false;
  178. //载入时,以何种方式编辑 源码和所见即所得 "source"和"wysiwyg"
  179. //config.startupMode = "wysiwyg";
  180. //载入时,是否显示框体的边框
  181. //config.startupOutlineBlocks = false;
  182. //是否载入样式文件
  183. // Load from the styles' styles folder (mystyles.js file).
  184. //config.stylesSet = 'mystyles';
  185. // Load from a relative URL.
  186. //config.stylesSet = 'mystyles:/editorstyles/styles.js';
  187. // Load from a full URL.
  188. //config.stylesSet = 'mystyles:http://www.example.com/editorstyles/styles.js';
  189. // Load from a list of definitions.
  190. //config.stylesSet = [
  191. //{ name : 'Strong Emphasis', element : 'strong' },
  192. //{ name : 'Emphasis', element : 'em' }, ... ];
  193. //起始的索引值
  194. //config.tabIndex = 0;
  195. //当用户键入TAB时,编辑器走过的空格数,( ) 当值为0时,焦点将移出编辑框
  196. //config.tabSpaces = 4;
  197. //默认使用的模板
  198. //config.templates = "default";
  199. //用逗号分隔的模板文件
  200. //config.templates_files = ['plugins/templates/templates/default.js'];
  201. //当使用模板时,“编辑内容将被替换”框是否选中
  202. //config.templates_replaceContent = true;
  203. //主题
  204. //config.theme = "default";
  205. //撤销的记录步数
  206. //config.undoStackSize = 20;
  207. //config.contentsCss = "/CKEditorAndCKFinder/ckeditor/css/mysitestyles.css";
  208. };
  209.  

更多关于PHP相关内容感兴趣的读者可查看jb51专题:《PHP扩展开发教程》、《PHP网络编程技巧总结》、《php curl用法总结》、《PHP数组(Array)操作技巧大全》、《PHP数据结构与算法教程》、《php程序设计算法总结》及《php字符串(string)用法总结

希望本文所述对大家PHP程序设计有所帮助。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号