码迷,mamicode.com
首页 > Web开发 > 详细

KindEditor图片上传

时间:2019-09-11 15:24:24      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:func   manager   public   temp   utf-8   move   art   copy   就是   

KindEditor参数配置
<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>

后台代码处理  

//特别需要注意的一点就是返回的error一定要用整数1或是0,别用字符串‘1‘或‘0‘
    public function uploads(Request $request)
    {

        if(!empty($_FILES)) {
            $file = $_FILES[‘imgFile‘];
            //原文件名
            $file_name = $file[‘name‘];
            //服务器上临时文件名
            $tmp_name = $file[‘tmp_name‘];
            //获得文件扩展名
            $temp_arr = explode(".", $file_name);
            $file_ext = array_pop($temp_arr);
            $file_ext = trim($file_ext);
            $file_ext = strtolower($file_ext);
            //保存路径
            $save_path = ‘uploads/article/‘;
            $save_url =‘http://‘.$_SERVER[‘HTTP_HOST‘]. ‘/uploads/article/‘;
            if (!file_exists($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]);

        }
    }

  

 

KindEditor图片上传

标签:func   manager   public   temp   utf-8   move   art   copy   就是   

原文地址:https://www.cnblogs.com/catyxiao/p/11506310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!