summernote js upload image

前端 未结 2 436
不知归路
不知归路 2021-01-19 07:55

I\'m using summernote version 0.8.1 (current).

It\'s working. But 1 thing I struggle with. Inserting an image, rather than putting base64 dataURL, I want to upload t

2条回答
  •  悲哀的现实
    2021-01-19 09:00

    This is how I integrated it with Codeigniter 3, Summernote 0.8.1:

    I am posting my working solution here so that anyone else can get some help or idea on how to implement summernote with image upload in CI 3 with CSRF.

    the javascript code:

    
    
     
     
    
    
    
    
    
    
    

    the codeigniter part:

     //add this line in your routes.php
     $route['summernote-image-upload'] = 'welcome/summernote-image-upload';
    
     //now add this method in your Welcome.php Controller:
     function summernote_image_upload() {
        if ($_FILES['image']['name']) {
            if (!$_FILES['image']['error']) {
                $ext = explode('.', $_FILES['image']['name']);
                $filename = underscore($ext[0]) . '.' . $ext[1];
                $destination = './public/images/summernote/' . $filename; //change path of the folder...
                $location = $_FILES["image"]["tmp_name"];
                move_uploaded_file($location, $destination);
                echo base_url() . 'public/images/summernote/' . $filename;
            } else {
                echo $message = 'The following error occured:  ' . $_FILES['image']['error'];
            }
        }
    }
    

    the HTML part:

       
       
    

    note if you face issue with CSRF (for any reason), then you can exclude the summernote ajax upload in your config.php file:

     $config['csrf_exclude_uris'] = array('summernote-image-upload');
    

提交回复
热议问题