当前位置:网站首页>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 ~
边栏推荐
- Calculate the odd sum of 1~n (1~100 as an example)
- JS实现文字滚动 跑马灯效果
- mysql数据库的存储
- 01 qemu 启动编译好的镜像 VFS: Unable to mount root fs on unknown-block(0,0)
- 数据库SQL语句汇总,持续更新......
- 拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
- '2'>' 10'==true? How does JS perform implicit type conversion?
- [paddleseg source code reading] paddleseg calculation dice
- Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
- Simple dialogue system -- text classification using transformer
猜你喜欢

JVM family -- heap analysis

Flink学习7:应用程序结构

*. No main manifest attribute in jar

10 reasons for not choosing to use free virtual hosts

'2'>' 10'==true? How does JS perform implicit type conversion?
![[PaddleSeg 源码阅读] PaddleSeg 自定义数据类](/img/88/37c535b371486db545abc392a685af.png)
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类

Objective-C description method and type method

Perf simple process for multithreaded profile

Select sorting and bubble sorting template
![[paddleseg source code reading] paddleseg custom data class](/img/88/37c535b371486db545abc392a685af.png)
[paddleseg source code reading] paddleseg custom data class
随机推荐
Evolution of MySQL database architecture
The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
Objective-C description method and type method
Flink学习8:数据的一致性
[PaddleSeg 源码阅读] PaddleSeg Transform 的 Normalize操作
CUDA basic knowledge
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
Redis cluster view the slots of each node
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
“软硬皆施”,助力建成新型云计算数据中心
Unity 绘制弹球和台球的运动轨迹
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
JVM family -- heap analysis
Pytest multi process / multi thread execution test case
What kind of experience is it when the Institute earns 20000 yuan a month!
postgresql 用户不能自己创建表格配置
Flink学习6:编程模型
选择排序与冒泡排序模板
如何远程办公更有效率 | 社区征文
Pandora IOT development board learning (HAL Library) - Experiment 6 independent watchdog experiment (learning notes)