php怎样让CKEditor能够上传图片、Flash等文件 | 胡鹏博客
首页 > php资料 > php怎样让CKEditor能够上传图片、Flash等文件
2012三月17

php怎样让CKEditor能够上传图片、Flash等文件

在PHP里使用 CKEditor可以在线编辑,那怎样上传图片呢,这时我们要考虑CKEditor和 CKFinder插件结合使用,能够灵活上传图片,flash,文件等.步骤如下。
1、首先下载

http://download.cksource.com/CKEditor/CKEditor/CKEditor%203.6.2/ckeditor_3.6.2.zip

http://download.cksource.com/CKFinder/CKFinder%20for%20PHP/2.1.1/ckfinder_php_2.1.1.zip

解压下载到的CKEditor ,放到网站的路径中即可,解压下载到的CKEditor放到与CKEditor同一目录中即可

 2.修改ckeditor/config.js 文件先修改这个函数成如下代码,分别设置皮肤,语言,工具条

CKEDITOR.editorConfig = function (config) {

    // Define changes to default configuration here. For example:

    // config.language = 'fr';

    // config.uiColor = '#AADC6E';

    config.skin = 'v2';
    config.language = 'zh-cn';
    config.toolbar = 'Full';
    config.toolbar_Full =
    [
             { name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] },

             { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },

             { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },

             { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },

             '/',

             { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },

             { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },

             { name: 'links', items : [ 'Link','Unlink','Anchor' ] },

             { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] },

             '/',

             { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },

             { name: 'colors', items : [ 'TextColor','BGColor' ] },

             { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] }

    ];

    config.toolbar_Basic =

    [

             ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']

    ];

 //第二步
    config.filebrowserBrowseUrl = 'ckfinder/ckfinder.html';

    config.filebrowserImageBrowseUrl = 'ckfinder/ckfinder.html?Type=Images';

    config.filebrowserFlashBrowseUrl = 'ckfinder/ckfinder.html?Type=Flash';

    config.filebrowserUploadUrl = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';

    config.filebrowserImageUploadUrl = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';

    config.filebrowserFlashUploadUrl = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
};
3、这时打开ckfinder下面的config.php文件,修改CheckAuthentication()()
返回值为true,代码如下。
public override bool CheckAuthentication()
         {
   // WARNING : DO NOT simply return "true". By doing so, you are allowing
 // "anyone" to upload and list the files in your server. You must implement
 // some kind of session validation here. Even something very simple as...

 // return isset($_SESSION['IsAuthorized']) && $_SESSION['IsAuthorized'];

 // ... where $_SESSION['IsAuthorized'] is set to "true" as soon as the
 // user logs in your system. To be able to use session variables don't
 // forget to add session_start() at the top of this file.

 //return false;
 Return true;
         }

就可以了。你可以写一个测试页面测试下啦,代码如下,只要你按照胡鹏博客这样子做的一定可以实现的,另外提醒一下,在做的时候一定要保持路径正确。

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<FORM METHOD="POST" ACTION="">
<TEXTAREA ID="txtContent"  NAME="ckeditor" ></TEXTAREA>
<INPUT TYPE="submit">
</FORM>
如果想更改保存路径和图片名称,请看胡鹏博客的另一篇文章 ckeditor+ckfinder 配置上传图片自定义图片路径及名称_博主自己改过

更多

文章作者:东莞seo
本文链接地址:http://www.seostudying.com/620.html
欢迎转载,转载请注明出处»胡鹏博客 [php怎样让CKEditor能够上传图片、Flash等文件]

本文目前尚无任何评论.
您必须在 登录 后才能发布评论.