当前位置:网站首页>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);
}
到此,大功告成~
边栏推荐
- Wechat official account web page authorization
- Package details_ Four access control characters_ Two details of protected
- 【读书会第十三期】视频文件的封装格式
- 如何有效远程办公之我见 | 社区征文
- How much does it cost to open a futures account in China? Where is it safe to open an account at present?
- warning: LF will be replaced by CRLF in XXXXXX
- Jenkins configures IP address access
- Pytest multi process / multi thread execution test case
- Huawei cloud Kunpeng engineer training (Guangxi University)
- [PaddleSeg 源码阅读] PaddleSeg 自定义数据类
猜你喜欢
How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
2022-07-03: there are 0 and 1 in the array. Be sure to flip an interval. Flip: 0 becomes 1, 1 becomes 0. What is the maximum number of 1 after turning? From little red book. 3.13 written examination.
渗透实战-SQLServer提权
三菱M70宏变量读取三菱M80公共变量采集三菱CNC变量读取采集三菱CNC远程刀补三菱机床在线刀补三菱数控在线测量
Why is it recommended that technologists write blogs?
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类
What kind of experience is it when the Institute earns 20000 yuan a month!
Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
JVM family -- heap analysis
Third party login initial version
随机推荐
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
Es network layer
SQL statement strengthening exercise (MySQL 8.0 as an example)
Why is it recommended that technologists write blogs?
Session learning diary 1
MySQL one master multiple slaves + linear replication
数据库SQL语句汇总,持续更新......
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
选择排序与冒泡排序模板
The new data center helps speed up the construction of a digital economy with data as a key element
Spa in SDP
【.NET+MQTT】.NET6 環境下實現MQTT通信,以及服務端、客戶端的雙邊消息訂閱與發布的代碼演示
Aperçu du code source futur - série juc
1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
Objective-C string class, array class
Development of digital collection trading platform development of digital collection platform
JVM family -- heap analysis
MySQL backup notes
Webhook triggers Jenkins for sonar detection
毕业总结