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]);
}
}