当前位置:网站首页>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 ~
边栏推荐
猜你喜欢

My opinion on how to effectively telecommute | community essay solicitation

Confession code collection, who says program apes don't understand romance

*. No main manifest attribute in jar

基于PHP的轻量企业销售管理系统

idea修改主体颜色

ctf-pikachu-CSRF

MySQL maxscale realizes read-write separation

干货!基于GAN的稀有样本生成

如何远程办公更有效率 | 社区征文

EV6 helps the product matrix, and Kia is making efforts in the high-end market. The global sales target in 2022 is 3.15 million?
随机推荐
Select sorting and bubble sorting template
函数计算异步任务能力介绍 - 任务触发去重
指针数组和数组指针
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
Katalon framework test web (XXVI) automatic email
数据库SQL语句汇总,持续更新......
【罗技】m720
[.NET + mqtt]. Mise en œuvre de la communication mqtt dans l'environnement net 6 et démonstration de code pour l'abonnement et la publication de messages bilatéraux du serveur et du client
华为云鲲鹏工程师培训(广西大学)
Flink学习8:数据的一致性
The new data center helps speed up the construction of a digital economy with data as a key element
“软硬皆施”,助力建成新型云计算数据中心
Aperçu du code source futur - série juc
Redis cluster uses Lua script. Lua script can also be used for different slots
[paddleseg source code reading] paddleseg calculation dice
Nbear introduction and use diagram
图解网络:什么是热备份路由器协议HSRP?
Is it safe to buy insurance for your children online? Do you want to buy a million dollar medical insurance for your children?
10 reasons for not choosing to use free virtual hosts
[paddleseg source code reading] paddleseg calculates Miou