当前位置:网站首页>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 ~
边栏推荐
- 三年进账35.31亿,这个江西老表要IPO了
- laravel admin里百度编辑器自定义路径和文件名
- Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
- 【罗技】m720
- Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
- MySQL maxscale realizes read-write separation
- 深度优先搜索简要讲解(附带基础题)
- Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
- 【.NET+MQTT】.NET6 環境下實現MQTT通信,以及服務端、客戶端的雙邊消息訂閱與發布的代碼演示
- The new data center helps speed up the construction of a digital economy with data as a key element
猜你喜欢
Storage of MySQL database
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.
渗透实战-guest账户-mimikatz-向日葵-sql提权-离线解密
图解网络:什么是热备份路由器协议HSRP?
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
*. No main manifest attribute in jar
Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
Objective-C description method and type method
Penetration practice - sqlserver empowerment
毕业设计:设计秒杀电商系统
随机推荐
透过JVM-SANDBOX源码,了解字节码增强技术原理
Objective C attribute keyword
量子力学习题
指针数组和数组指针
Katalon framework tests web (XXI) to obtain element attribute assertions
Why is it recommended that technologists write blogs?
渗透实战-guest账户-mimikatz-向日葵-sql提权-离线解密
STM32 external DHT11 display temperature and humidity
JDBC advanced
I Build a simple microservice project
Katalon中控件的参数化
Database SQL statement summary, continuous update
Mindmanager2022 efficient and easy to use office mind map MindManager
Es network layer
ctf-pikachu-CSRF
A review of reverse reinforcement learning at Virginia Tech (VT)
MySQL one master multiple slaves + linear replication
JSON string conversion in unity
CUDA basic knowledge
Idea configuration 360zip open by default -- external tools