The "imgupload.php" is a PHP script that can be used to upload image files on server, with CKEditor, and use them automatically in the editor's contents.

- You can download the script from this link: CKEditor Image Upload.

• To test the script: Demo
For comments, questions, or any issue related to this addon, write on Forum, in the "Scripts from Website" category.


1. To use this addon in CKEditor, Download the script and copy the "imgupload.php" file in the "ckeditor/plugins/" folder. Or, copy the code bellow, and add it into an "imgupload.php" file in "ckeditor/plugins/" folder.
2. Change the value of $upload_dir variable (line 5), with the path of images-directory on your server, RELATIVE TO THE ROOT OF YOUR WEBSITE ON SERVER.
3. By default, if the uploaded file name exists on server, it will be renamed with "filename_NR.ext" (NR is a number). If you want to Overwrite the existing file, set value of 0 to RENAME_F (line 9).
4. Sets CHMOD writable permision (0777) to image-upload folder on your server (if on Linux system), to allow PHP to upload the files.
5. Enable the plugin by adding the filebrowserImageUploadUrl parameter in CKEditor configuration on your page:
CKEDITOR.replace('textareaId', {
 "filebrowserImageUploadUrl": "/path_to/ckeditor/plugins/imgupload.php"


Click on image

imgbrowse Upload extension

Code of imgupload.php

- Click to select it.
// PHP Upload Script for CKEditor:

$upload_dir = '/upload_dir/';

// If 1 and filename exists, RENAME file, adding "_NR" to the end of filename (name_1.ext, name_2.ext, ..)
// If 0, will OVERWRITE the existing file
define('RENAME_F', 1);

$imgsets = array(
 'maxsize' => 2000, // maximum file size, in KiloBytes (2 MB)
 'maxwidth' => 900, // maximum allowed width, in pixels
 'maxheight' => 800, // maximum allowed height, in pixels
 'minwidth' => 10, // minimum allowed width, in pixels
 'minheight' => 10, // minimum allowed height, in pixels
 'type' => array('bmp', 'gif', 'jpg', 'jpe', 'png'), // allowed extensions

$re = '';

if(isset($_FILES['upload']) && strlen($_FILES['upload']['name']) > 1) {
 $upload_dir = trim($upload_dir, '/') .'/';
 define('IMG_NAME', preg_replace('/\.(.+?)$/i', '', basename($_FILES['upload']['name']))); //get filename without extension

 // get protocol and host name to send the absolute image path to CKEditor
 $protocol = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
 $site = $protocol. $_SERVER['SERVER_NAME'] .'/';
 $sepext = explode('.', strtolower($_FILES['upload']['name']));
 $type = end($sepext); // gets extension
 list($width, $height) = getimagesize($_FILES['upload']['tmp_name']); // gets image width and height
 $err = ''; // to store the errors

 //set filename; if file exists, and RENAME_F is 1, set "img_name_I"
 // $p = dir-path, $fn=filename to check, $ex=extension $i=index to rename
 function setFName($p, $fn, $ex, $i){
 if(RENAME_F ==1 && file_exists($p .$fn .$ex)) return setFName($p, IMG_NAME .'_'. ($i +1), $ex, ($i +1));
 else return $fn .$ex;
 $img_name = setFName($_SERVER['DOCUMENT_ROOT'] .'/'. $upload_dir, IMG_NAME, ".$type", 0);
 $uploadpath = $_SERVER['DOCUMENT_ROOT'] .'/'. $upload_dir . $img_name; // full file path

 // Checks if the file has allowed type, size, width and height (for images)
 if(!in_array($type, $imgsets['type'])) $err .= 'The file: '. $_FILES['upload']['name']. ' has not the allowed extension type.';
 if($_FILES['upload']['size'] > $imgsets['maxsize']*1000) $err .= '\\n Maximum file size must be: '. $imgsets['maxsize']. ' KB.';
 if(isset($width) && isset($height)) {
 if($width > $imgsets['maxwidth'] || $height > $imgsets['maxheight']) $err .= '\\n Width x Height = '. $width .' x '. $height .' \\n The maximum Width x Height must be: '. $imgsets['maxwidth']. ' x '. $imgsets['maxheight'];
 if($width < $imgsets['minwidth'] || $height < $imgsets['minheight']) $err .= '\\n Width x Height = '. $width .' x '. $height .'\\n The minimum Width x Height must be: '. $imgsets['minwidth']. ' x '. $imgsets['minheight'];

 // If no errors, upload the image, else, output the errors
 if($err == '') {
 if(move_uploaded_file($_FILES['upload']['tmp_name'], $uploadpath)) {
 $CKEditorFuncNum = $_GET['CKEditorFuncNum'];
 $url = $site. $upload_dir . $img_name;
 $msg = IMG_NAME .'.'. $type .' successfully uploaded: \\n- Size: '. number_format($_FILES['upload']['size']/1024, 3, '.', '') .' KB \\n- Image Width x Height: '. $width. ' x '. $height;
 $re = "$CKEditorFuncNum, '$url', '$msg')";
 else $re = 'alert("Unable to upload the file")';
 else $re = 'alert("'. $err .'")';
echo '<script>'. $re .';</script>';

Daily Test with Code Example

Which HTML5 tag defines marked text? (can be used to highlight parts of text)
<mark> <embed> <span>
<p>Free corses: <mark></mark> for Web Development.</p>
Which CSS pseudo-class adds a style to an element when the mouse is over it?
:focus :hover :active
a:hover {
  font-weight: bold;
  color: #00da01;
Click on the function which returns a string value that represents the number rounded to the x digits after the decimal point.
toPrecision(x) toFixed(x) floor(x)
var num = 12.34567;
num = num.toFixed(2);
alert(num);       // 12.35
Indicate the PHP function which reads an entire file into an array.
[) file() readfile()
$arr = file("a_file.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
CKEditor Free Image Uploader Addon

Last accessed pages

  1. Follow the mouse cursor with a DIV inside a Parent (2703)
  2. Register and show online users and visitors (23278)
  3. Node.js Move and Copy Directory (1127)
  4. SHA1 Encrypt data in JavaScript (8256)
  5. Split an alphanumeric string into Array in JavaScript (634)

Popular pages this month

  1. Read Excel file data in PHP - PhpExcelReader (390)
  2. PhpSpreadsheet - Read, Write Excel and LibreOffice Calc files (332)
  3. Register and show online users and visitors (302)
  4. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (234)
  5. Insert, Select and Update NULL value in MySQL (223)