在dcat-admin中使用ckeditor实现文件上传示例
Laravel  /  管理员 发布于 10个月前   542
在dcat-admin中使用ckeditor实现文件上传功能
去掉预览中的文字
# 为了去掉预览中的文字
在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', ],]);
需要的拿走测试!
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号