ckeditor文件上传并在dcat中使用
去掉预览中的文字
# 为了去掉预览中的文字
在ckeditor/plugins/image/dialogs/image.js
搜索“d.config.image_previewText”,把(d.config.image_previewText||”)加粗的内容全删了。
开启上传功能
在ckeditor/plugins/image/dialogs/image.js
搜索:id:’Upload’,hidden:!0
实际上上传功能被隐藏了,把上面的!0改成false。
定义上传文件时的action
config.filebrowserUploadUrl = '/index.php?action=address&do=upload'; //地址自定义
在php处理文件中加入upload方法;
$name = 'upload'; if ($request->hasFile($name)){ //获取文件
$file = $request->file($name); $time = date('Ymd',time()); // 文件是否上传成功
if ($file->isValid()) { // 获取文件相关信息
$originalName = $file->getClientOriginalName(); // 文件原名
$ext = $file->getClientOriginalExtension(); // 扩展名
$realPath = $file->getRealPath(); //临时文件的绝对路径
$type = $file->getClientMimeType(); // image/jpeg // 上传文件
$filename = uniqid() . '.' . $ext; $path = 'editor/'.$time.'/'.$filename; //这里的uploads是配置文件的名称
$bool = Storage::disk('admin')->put('/'.$path, file_get_contents($realPath)); //判断是否创建成功
if (!$bool) return response()->json([ 'uploaded' => 0, 'error' => '上传失败',
]); return response()->json([ 'uploaded' => 1, "fileName" => $filename, "url" => '/upload/'.$path ]); } } return response()->json([ 'uploaded' => 0, 'error' => '上传失败',
]);```
##### bootstrap中引用
> 注册前端组件别名
```php
//(/dcat/editor/ 即你ckeditor存放目录,
//这里放在了,public/dcat/editor/ckeditor)
Admin::asset()->alias('@ckeditor', [
'js' => [ '/dcat/editor/ckeditor/ckeditor.js', '/dcat/editor/ckeditor/adapters/jquery.js', ],]);
本作品采用《CC 协议》,转载必须注明作者和本文链接