KindEditor image upload

KindEditor parameter configuration
<script>
    KindEditor.ready(function(K) {
        var editor1 = K.create('textarea[name="content"]', {
            uploadJson : '{{asset('/blue_cross_admin/article/uploads')}}',
            allowFileManager : false,
            items:['source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste',
                'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                'superscript', '|', 'selectall', '-',
                'title', 'fontname', 'fontsize','forecolor','hilitecolor', '|', 'textcolor', 'bgcolor', 'bold',
                'italic', 'underline', 'strikethrough', 'removeformat', '|', 'image', 'hr', 'emoticons', 'link', 'unlink', '|', 'about'],
        });
        prettyPrint();
    });
</script>

Background code processing  

// Of particular note is that the returned error must use an integer of 0 or 1, with the string do not '1' or '0' 
    public function uploads (the Request Request $) 
    { 

        IF (! Empty ($ _ the FILES)) { 
            file = $ _FILES $ [ 'imgfile']; 
            // original filename 
            $ file_name = $ file [ 'name']; 
            // temporary file on the server name 
            $ = $ tmp_name file [ 'tmp_name']; 
            // get the file extension 
            temp_arr the explode = $ (, $ file_name "."); 
            $ = file_ext array_pop ($ temp_arr); 
            $ file_ext = TRIM ($ file_ext); 
            $ file_ext = strtolower ($ file_ext); 
            // save path 
            $ save_path = 'uploads / Article This article was / ';  
            $ save_url =' HTTP: // '.$_SERVER['HTTP_HOST']. '/uploads/article/';
            IF (the file_exists (the save_path $)!) {
                mkdir($save_path);
            }
            //新文件名
            $new_file_name = uniqid() . "." . $file_ext;
            $file_path = $save_path . $new_file_name;
            //移动文件
            move_uploaded_file($tmp_name, $file_path);
            $file_url = $save_url . $new_file_name;
            //输出文件
            header('Content-type: text/html; charset=UTF-8');
            return response()->json(['error' => 0, 'url' => $file_url]);

        }
    }

  

 

Guess you like

Origin www.cnblogs.com/catyxiao/p/11506310.html