John's little part of the web

John's home page

2011-12-01 12:00:00

I am using the CK Editor here with CodeIgnitor using the ckeditor_helper from here.  The helper is placed in the CodeIgnitor helper folder in the application directory which allows the helper to be called.  The next step is to load the helper before calling it with the $this->load->helper('ckeditor').  The next step is to display the editor in the brower by setting the name of the text area to be used in the parmaters passed the the help function.

I also needed to update images which is not supported out of the box but can be accomplish by adding another parameter and creating a uploader.  The below code shows the finally setting in the browser.

<textarea cols="60" name="FCKeditor1" rows="8"><?php echo set_value('contents'); ?></textarea>
$parm = array(
    //ID of the textarea that will be replaced
    'id'  =>  'FCKeditor1',
    'path' => 'scripts/ckeditor',
    'config' => array(
            'filebrowserImageUploadUrl' => site_url('uploader?type=file.jpg')
            ),
        );

echo display_ckeditor($parm);    
?>

 

class Uploader extends CI_Controller
{
    function Uploader()
    {
        parent::__construct();
    }

    function index()
    {
        $upload_file = $this->image($_FILES["upload"]["name"]);
        if(isset($upload_file['data']['upload_data']['file_name']) && trim($upload_file['data']['upload_data']['file_name']) != '')
        {
            $funcNum = $_GET['CKEditorFuncNum'];
            $CKEditor = $_GET['CKEditor'];
            $langCode = $_GET['langCode'];
            $url = site_url('images') . '/' . $upload_file['data']['upload_data']['file_name'];
            $message = '';
           
            echo "";
        } else {
            echo $upload_file['message']['error'];
        }
    }

    function image($filenames = '')
    {
        $config['upload_path'] = './images/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '300';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $this->load->library('upload', $config);

        $result['status'] = 0;
        $result['message'] = 'fail';
        $result['data'] = array();
        if ( ! $this->upload->do_upload('upload'))
        {
            $error = array('error' => $this->upload->display_errors());
            $result['message'] = $error;
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
            $result['status'] = 1;
            $result['message'] = 'Upload OK';
            $result['data'] = $data;
        }

        return $result;
    }
}

 

Search using bing

this is a test