How To Upload and Insert image in CKEditor using PHP

Spread the love

Today we will see how to upload and insert image in CKEditor using PHP, then first of all we will download CKEditor and apply in our website if you don’t know how to download CKEditor then I have told in last blog how to download CKEditor.

How to Download CKEditor ?

Click Here

After downloading, we will follow the steps given below.

Step 1: Create index.php File.

If you want to add CKEditor online then you have to add CDN of CKEditor online which is given below.

Online CKEditor CDN Add

<link rel="stylesheet" href="" />
<script src=""></script>
<script src=""></script>
<script src=""></script>

<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="" />
<script src=""></script>
<script src=""></script>
<script src=""></script>

<textarea id="ckeditor" name="text">
 CKEDITOR.replace( 'text', {
  height: 300,
  filebrowserUploadUrl: "upload.php"

Step 2: Create upload.php File.

Create an upload.php file and paste the following code in it



 $file = $_FILES['upload']['tmp_name'];
 $file_name = $_FILES['upload']['name'];
 $file_name_array = explode(".", $file_name);
 $extension = end($file_name_array);
 $new_image_name = rand() . '.' . $extension;
 chmod('upload', 0777);
 $allowed_extension = array("jpg", "gif", "png");
 if(in_array($extension, $allowed_extension))
  move_uploaded_file($file, 'upload/' . $new_image_name);
  $function_number = $_GET['CKEditorFuncNum'];
  $url = 'upload/' . $new_image_name;
  $message = '';
  echo "<script type='text/javascript'>$function_number, '$url', '$message');</script>";


Note: Create a folder named upload to store the image.

Spread the love

Related Posts

Leave a Reply

Your email address will not be published.