Thinkphp使用CKEditor4

“fileName”: “test.jpg”,

“url”: “/files/test.jpg”,

“error”: {

“message”: “A file with the same name already exists. The uploaded file was renamed to “test.jpg”.”

}

}

上传失败返回:

{

“uploaded”: 0,

“error”: {

“message”: “The file is too big.”

}

}

后端上传图片的代码:

/**

  • @name=‘上传图片’

*/

public function uploadPic()

{

//注明:ckeditor是使用ajax上传图片,而不是用表单提交,因此不能使用request()->file()接收图片,只能用$_FILES

$name = $_FILES[‘upload’][‘name’];

$size = $_FILES[‘upload’][‘size’];

if($size > 102421000){

$arr= array(

“uploaded” => 0,

“error” => “上传的图片大小不能超过2M”

);

exit(json_encode($arr));

}

e x t e n s i o n = p a t h I n f o ( extension = pathInfo( extension=pathInfo(name,PATHINFO_EXTENSION);

$types = array(“jpg”,“bmp”,“gif”,“png”);

if(in_array( e x t e n s i o n , extension, extension,types)){

//以日期为文件夹名,如public/uploads/20210327/

$dateFolder = date(“Ymd”,time());

p a t h = R O O T P A T H . ′ p u b l i c / u p l o a d s / ′ . path = ROOT_PATH . 'public/uploads/'. path=ROOTPATH.public/uploads/.dateFolder.DS;

if(!file_exists($path)){

mkdir($path,0777,true);

}

i m g n a m e = s t r r e p l a c e ( ′ . ′ , ′ ′ , u n i q i d ( " " , T R U E ) ) . " . " . img_name = str_replace('.','',uniqid("",TRUE)).".". imgname=strreplace(.,′′,uniqid("",TRUE)).".".extension; //图片名称

$save_path = p a t h . path. path.img_name; //保存路径

i m g p a t h = ′ / u p l o a d s / ′ . img_path = '/uploads/'. imgpath=/uploads/.dateFolder.DS.$img_name; //图片路径

move_uploaded_file( F I L E S [ ′ u p l o a d ′ ] [ ′ t m p n a m e ′ ] , _FILES['upload']['tmp_name'], FILES[upload][tmpname],save_path);

$arr= array(

“uploaded” => 1,

“fileName” => $img_name,

“url” => $img_path

);

}else{

$arr= array(

“uploaded” => 0,

“error” => “图片格式不正确(只能上传.jpg/.gif/.bmp/.png类型的文件)”

);

}

return json_encode($arr);

}

六、js里获取ckeditor里的内容

七、使用颜色插件

1、需要下载三个插件(缺一不可),下载地址:

https://ckeditor.com/cke4/addon/colorbutton

https://ckeditor.com/cke4/addon/floatpanel

https://ckeditor.com/cke4/addon/panelbutton

2、下载好的插件解压到ckeditor\plugins目录里

3、加载插件

方式一:在ckeditor/config.js文件中,添加插件的配置,如下:

CKEDITOR.editorConfig = function( config ) {

…省略前面的代码

//加载插件

config.extraPlugins = ‘colorbutton,panelbutton,floatpanel’;

}

方式二:在js里初始化editor时,添加插件的配置

八、自定义工具栏配置

在ckeditor/config.js文件中设置

CKEDITOR.editorConfig = function( config ) {

//工具栏设置

config.toolbar = ‘MyToolbar’;

config.toolbar_Full = [

{ name: ‘document’, items : [ ‘Source’,‘-’,‘Save’,‘NewPage’,‘DocProps’,‘Preview’,‘Print’,‘-’,‘Templates’ ] },

{ name: ‘clipboard’, items : [ ‘Cut’,‘Copy’,‘Paste’,‘PasteText’,‘PasteFromWord’,‘-’,‘Undo’,‘Redo’ ] },

{ name: ‘editing’, items : [ ‘Find’,‘Replace’,‘-’,‘SelectAll’,‘-’,‘SpellChecker’, ‘Scayt’ ] },

{ name: ‘forms’, items : [ ‘Form’, ‘Checkbox’, ‘Radio’, ‘TextField’, ‘Textarea’, ‘Select’, ‘Button’, ‘ImageButton’,

‘HiddenField’ ] },

‘/’,

{ name: ‘basicstyles’, items : [ ‘Bold’,‘Italic’,‘Underline’,‘Strike’,‘Subscript’,‘Superscript’,‘-’,‘RemoveFormat’ ] },

{ name: ‘paragraph’, items : [ ‘NumberedList’,‘BulletedList’,‘-’,‘Outdent’,‘Indent’,‘-’,‘Blockquote’,‘CreateDiv’,

‘-’,‘JustifyLeft’,‘JustifyCenter’,‘JustifyRight’,‘JustifyBlock’,‘-’,‘BidiLtr’,‘BidiRtl’ ] },

{ name: ‘links’, items : [ ‘Link’,‘Unlink’,‘Anchor’ ] },

{ name: ‘insert’, items : [ ‘Image’,‘Flash’,‘Table’,‘HorizontalRule’,‘Smiley’,‘SpecialChar’,‘PageBreak’,‘Iframe’ ] },

‘/’,

{ name: ‘styles’, items : [ ‘Styles’,‘Format’,‘Font’,‘FontSize’ ] },

{ name: ‘colors’, items : [ ‘TextColor’,‘BGColor’ ] },

{ name: ‘tools’, items : [ ‘Maximize’, ‘ShowBlocks’,‘-’,‘About’ ] }

];

config.toolbar_Basic = [

[‘Bold’, ‘Italic’, ‘-’, ‘NumberedList’, ‘BulletedList’, ‘-’, ‘Link’, ‘Unlink’,‘-’,‘About’]

];

//自定义

config.toolbar_MyToolbar =[

//加粗 斜体, 下划线 穿过线 下标字 上标字

[‘Bold’,‘Italic’,‘Underline’,‘Strike’,‘Subscript’,‘Superscript’],

// 数字列表 实体列表 减小缩进 增大缩进

[‘NumberedList’,‘BulletedList’,‘-’,‘Outdent’,‘Indent’],

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助

因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
3)]

[外链图片转存中…(img-HHLqJYrX-1715768041235)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值