Posted inTechnology / Ajax / JavaScript / jQuery / php / Programming

PHP upload custom file in ckeditor Example

Today, We want to share with you PHP upload custom file in ckeditor Example.In this post we will show you custom file CKEDITOR, Image Upload in PHP, hear for PHP ckeditor upload image from computer we will give you demo and example for implement.In this post, we will learn about PHP Uploading Image File in Ckeditor with an example.

PHP upload custom file in ckeditor Example

There are the Following The simple About PHP upload custom file in ckeditor Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop PHP – How to custom file uploading with CKEDITOR?, so the some major files and Directory structures for this example is following below.

  • make “Images” Folder
  • index.php
  • upload.php

step : 2 create index.php file

index.php

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.




  
  
  PHP File Manager Integration with Validation Example
  


How to upload custome file in ckeditor in php

PHP Simple upload custom file in ckeditor Example

step : 2 Make Serever side Source Code

PHP create upload.php file

 '/postimages/',
);

$configImg = array(
    // 'maxsize' => 2000,    
    // 'maxwidth' => 900,    
    // 'maxheight' => 800,    
    'minwidth' => 10,      
    'minheight' => 10,
    'type' => array('bmp', 'gif', 'jpg', 'jpeg', 'png'),
);


define('RENAME_F', 1);

$dataresults = '';
if(isset($_FILES['upload']) && strlen($_FILES['upload']['name']) >1) {
    define('F_NAME', preg_replace('/\.(.+?)$/i', '', basename($_FILES['upload']['name']))); 

 
    $site = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'].'/';
    $sepext = explode('.', strtolower($_FILES['upload']['name']));
    $type = end($sepext);    // gets extension
    $destination_folder = in_array($type, $configImg['type']) ? $destination_folder['img'] : $destination_folder['audio'];
    $destination_folder = trim($destination_folder, '/') .'/';


    if(in_array($type, $configImg['type'])){
        // list($width, $height) = getimagesize($_FILES['upload']['tmp_name']);  // image width and height
        if(isset($width) && isset($height)) {
            if($width > $configImg['maxwidth'] || $height > $configImg['maxheight']) $dataresults .= '\\n Width x Height = '. $width .' x '. $height .' \\n The maximum Width x Height must be: '. $configImg['maxwidth']. ' x '. $configImg['maxheight'];
            if($width < $configImg['minwidth'] || $height < $configImg['minheight']) $dataresults .= '\\n Width x Height = '. $width .' x '. $height .'\\n The minimum Width x Height must be: '. $configImg['minwidth']. ' x '. $configImg['minheight'];
            if($_FILES['upload']['size'] > $configImg['maxsize']*1000) $dataresults .= '\\n Maximum file size must be: '. $configImg['maxsize']. ' KB.';
        }
    }
  
    else $dataresults .= 'The file: '. $_FILES['upload']['name']. ' has not the allowed Any More extension type.';


    function fileNameSet($p, $fn, $ex, $i){
        if(RENAME_F ==1 && file_exists($p .$fn .$ex)) return fileNameSet($p, F_NAME .'_'. ($i +1), $ex, ($i +1));
        else return $fn .$ex;
    }

    $f_name = fileNameSet($_SERVER['DOCUMENT_ROOT'] .'/'. $destination_folder, F_NAME, ".$type", 0);
    $relstorepath = $_SERVER['DOCUMENT_ROOT'] .'/'. $destination_folder . $f_name;  // full file path

    if($dataresults == '') {
        // print_r($_FILES);exit;
        if(move_uploaded_file($_FILES['upload']['tmp_name'], $relstorepath)) {
            $CKEditorFuncNum = $_GET['CKEditorFuncNum'];
            $url = $site. $destination_folder . $f_name;
            $msg = F_NAME .'.'. $type .' successfully uploaded: \\n- Size: '. number_format($_FILES['upload']['size']/1024, 2, '.', '') .' KB';
            $dataresults = in_array($type, $configImg['type']) ? "window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url', '$msg')"  //for img
           : 'var editorObj = window.parent.CKEDITOR; for(var ckid in editorObj.instances) { if(editorObj.instances[ckid].focusManager.hasFocus) break;} editorObj.instances[ckid].insertHtml(\'\', \'unfiltered_html\'); alert("'. $msg .'"); var dialog = editorObj.dialog.getCurrent();  dialog.hide();';
        }
        else $dataresults = 'alert("Sorry, Unable to upload the file")';
    }
    else $dataresults = 'alert("'. $dataresults .'")';
}

@header('Content-type: text/html; charset=utf-8');
echo '';
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP upload custom file in ckeditor Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype