当前位置:网站首页>User defined path and file name of Baidu editor in laravel admin
User defined path and file name of Baidu editor in laravel admin
2022-07-04 04:10:00 【king2wang】
Recently I met a problem , from word Copy the picture and paste it into the background rich text box , Pictures are always overwritten after saving , Later, it was found that Baidu editor uses the file name of the source file when saving by default md5() Current file name , And from word Pictures copied in , The file names are the same by default , So it leads to the picture coverage , So I decided to customize the path and file name ....
1. Custom path
This is very simple , find config/ueditor.php, find imagePathFormat Just modify it , There are other upload paths , If necessary, you can modify it accordingly , Include (scrawlPathFormat、snapscreenPathFormat、catcherPathFormat、filePathFormat etc. )

2. Custom filename , This is a little troublesome , Because there is no direct configuration , Only the source code can be modified ,
Source location :vendor/codingyu/laravel-ueditor/src/StorageManager.php
find getFilename() Method
The original code is : Get the name of the source file and proceed according to ueditor.hash_filename The configuration of md5() Encrypted or unencrypted , But no matter whether it is encrypted or not, as long as the name of the source file is the same , Then the file will be overwritten .
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);
}The modified code : In view of this situation , We can use the way of customizing the file name , Here is still the previous logic , When ueditor.hash_filename=true Customize the name when ( Here we use timestamp plus random string ), Otherwise, use the source file name
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);
}Here we are , Be accomplished ~
边栏推荐
- PostgreSQL users cannot create table configurations by themselves
- JSON string conversion in unity
- Confession code collection, who says program apes don't understand romance
- 01 qemu 启动编译好的镜像 VFS: Unable to mount root fs on unknown-block(0,0)
- Pandora IOT development board learning (HAL Library) - Experiment 6 independent watchdog experiment (learning notes)
- [paddleseg source code reading] normalize operation of paddleseg transform
- Rhcsa-- day one
- 【CSRF-01】跨站请求伪造漏洞基础原理及攻防
- My opinion on how to effectively telecommute | community essay solicitation
- JVM family -- monitoring tools
猜你喜欢

The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO

Rhcsa-- day one

透过JVM-SANDBOX源码,了解字节码增强技术原理

【CSRF-01】跨站请求伪造漏洞基础原理及攻防

用于TCP协议交互的TCPClientDemo

JVM family -- heap analysis

LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)

Katalon中控件的参数化

SQL statement strengthening exercise (MySQL 8.0 as an example)

02 ls 命令的具体实现
随机推荐
Katalon使用script实现查询List大小
深入浅出对话系统——使用Transformer进行文本分类
毕业设计:设计秒杀电商系统
MySQL maxscale realizes read-write separation
【webrtc】m98 ninja 构建和编译指令
Unity 绘制弹球和台球的运动轨迹
1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
“软硬皆施”,助力建成新型云计算数据中心
The new data center helps speed up the construction of a digital economy with data as a key element
JDBC 进阶
Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
支持首次触发的 Go Ticker
functools下的reduce函数
Huawei cloud Kunpeng engineer training (Guangxi University)
Redis cluster view the slots of each node
思考的小记录
Flink学习6:编程模型
三年进账35.31亿,这个江西老表要IPO了
如何远程办公更有效率 | 社区征文