File Uploading for CKEditor using CodeIgniter


I know, I know that I haven’t uploaded the source code of my simple project, Blog Manager, yet to github. I have already created the repository, though. This is just a notification update on Blog Manager.

As my boss really planned to make it a wordpress like text editor when adding a post, so I work on CKEditor, a great editor I must say, but quite tiring to create the file browser (it’s just me I think). For now, I have also added the Blog Manager category on this blog, Various Talks.

AS for your information, to create simple upload dialog on CKEditor, you can use the code chunk below for PHP.

PS. I was inspired by this post. So I lazily changed it for CodeIgniter. Yeah because I’d rather change than rethink about the algorithm and read a long example. LOL

public function addphoto($blogID){
	$this->load->model('BlogModel'); // the model that communicate with blog

	$config['upload_path'] = './uploads/';
	$config['allowed_types'] = 'gif|jpg|jpeg|png';
	$config['overwrite'] = FALSE;
	$this->load->library('upload');


	$funcNum = $this->input->get('CKEditorFuncNum'); //$_GET['CKEditorFuncNum']
	$this->upload->initialize($config);
		
	if (!$this->upload->do_upload('upload')){ // upload the file, 'upload' is the name of the field from CKEditor
		 // failed upload
		$message = "Upload failed on blog manager server.";
		$url = '';
	
	}else{ // success copy to wp server
		$upload_result = base_url() . 'uploads/'. $this->upload->data()['file_name'];
		$upload_name = $this->upload->data()['file_name'];

		// after finished uploading, it will receive a URL
		$url = $this->BlogModel->UploadImage($blogID, $upload_result, $upload_name); 

		$message = 'Upload success!';
	}
	echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>";
}

Feel free to notify me if you’re interested in this.

Be free to visit it in here!

Advertisements

Author: Aditya Yedija Situmeang

Developer, Lover, Christian, Omnomnomnivore, Gamer.

2 thoughts on “File Uploading for CKEditor using CodeIgniter”

  1. it works thanks ,
    It took me a while to figure out how to upload images with Ckeditor.
    your articles help me a lot.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s