当前位置:网站首页>laravel admin里百度编辑器自定义路径和文件名
laravel admin里百度编辑器自定义路径和文件名
2022-07-04 03:47:00 【king2wang】
最近遇见一个问题,从word里复制图片粘贴到后台富文本框里,保存后图片老是被覆盖,后来发现是由于百度编辑器默认保存的时候是使用源文件的文件名md5()后当文件名,而从word里复制的图片,文件名默认都是一样的,所以导致了图片覆盖的情况,所以决定自定义路径和文件名。。。。
1.自定义路径
这个很简单,找到config/ueditor.php,找到imagePathFormat进行修改即可,还有其他情况下上传路径,需要的话都可以对应修改,包括(scrawlPathFormat、snapscreenPathFormat、catcherPathFormat、filePathFormat等)

2.自定义文件名,这个就稍微麻烦一点了,因为没有直接的配置,只能修改源代码,
源码位置:vendor/codingyu/laravel-ueditor/src/StorageManager.php
找到getFilename()方法
原来的代码是:获取源文件的名字后进行根据ueditor.hash_filename配置进行md5()加密或不加密,但不管是否加密只要源文件名字是一样的,那么就会出现文件被覆盖的情况。
protected function getFilename(UploadedFile $file, array $config)
{
$ext = '.' . $file->getClientOriginalExtension();
$filename = config('ueditor.hash_filename') ? md5($file->getFilename()) . $ext : $file->getClientOriginalName();
return $this->formatPath($config['path_format'], $filename);
}修改后的代码:鉴于这种情况,我们就可以使用自定义文件名的方式,这里依然延续之前的逻辑,当ueditor.hash_filename=true的时候再自定义名字(这里使用的是时间戳加随机字符串),否则就使用源文件名
protected function getFilename(UploadedFile $file, array $config)
{
$ext = '.' . $file->getClientOriginalExtension();
$rand = mt_rand(0, pow(10, 6) - 1);
$filename = config('ueditor.hash_filename') ? time().$rand . $ext : $file->getClientOriginalName();
return $this->formatPath($config['path_format'], $filename);
}到此,大功告成~
边栏推荐
- 函数计算异步任务能力介绍 - 任务触发去重
- Katalon framework tests web (XXI) to obtain element attribute assertions
- static hostname; transient hostname; pretty hostname
- CSP drawing
- CUDA basic knowledge
- Katalon框架测试web(二十一)获取元素属性断言
- Objective C attribute keyword
- Database SQL statement summary, continuous update
- system information
- Penetration practice - sqlserver empowerment
猜你喜欢
![[PaddleSeg 源码阅读] PaddleSeg 自定义数据类](/img/88/37c535b371486db545abc392a685af.png)
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类

MySQL maxscale realizes read-write separation

2022-07-03:数组里有0和1,一定要翻转一个区间,翻转:0变1,1变0。 请问翻转后可以使得1的个数最多是多少? 来自小红书。3.13笔试。

pytest多进程/多线程执行测试用例

拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。

Select sorting and bubble sorting template

Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption

Go 语言入门很简单:Go 实现凯撒密码

Mindmanager2022 efficient and easy to use office mind map MindManager

What are the virtual machine software? What are their respective functions?
随机推荐
Session learning diary 1
[PaddleSeg 源码阅读] PaddleSeg Transform 的 Normalize操作
Sales management system of lightweight enterprises based on PHP
Redis notes (I) Linux installation process of redis
选择排序与冒泡排序模板
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
How to dynamically cache components in Vue multi-level route nesting
【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(上)
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
SDP中的SPA
logistic regression
1289_FreeRTOS中vTaskSuspend()接口实现分析
Select sorting and bubble sorting template
Future源碼一觀-JUC系列
毕业总结
functools下的reduce函数
1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
Formulaire day05
数据库SQL语句汇总,持续更新......
Package details_ Four access control characters_ Two details of protected