当前位置:网站首页>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 ~
边栏推荐
- Brief explanation of depth first search (with basic questions)
- Unity 绘制弹球和台球的运动轨迹
- LevelDB源码解读-SkipList
- [Huawei cloud IOT] reading notes, "Internet of things: core technology and security of the Internet of things", Chapter 3 (I)
- Katalon framework tests web (XXI) to obtain element attribute assertions
- pytest多进程/多线程执行测试用例
- Simple dialogue system -- text classification using transformer
- Reduce function under functools
- I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
- Class summation, shortest row
猜你喜欢

postgresql 用户不能自己创建表格配置

微信公众号网页授权

Idea configuration 360zip open by default -- external tools

用于TCP协议交互的TCPClientDemo

Katalon中控件的参数化

Pytest multi process / multi thread execution test case

Mitsubishi M70 macro variable reading Mitsubishi M80 public variable acquisition Mitsubishi CNC variable reading acquisition Mitsubishi CNC remote tool compensation Mitsubishi machine tool online tool

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

JSON string conversion in unity

Flink学习6:编程模型
随机推荐
Reduce function under functools
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
Database SQL statement summary, continuous update
SDP中的SPA
Deep thinking on investment
The difference between bagging and boosting in machine learning
[PaddleSeg 源码阅读] PaddleSeg Transform 的 Normalize操作
JDBC advanced
*. No main manifest attribute in jar
[book club issue 13] packaging format of video files
There is a problem that the package cannot be parsed in the like project
Msgraphmailbag - search only driveitems of file types
Myslq delete followed by limit
用于TCP协议交互的TCPClientDemo
JVM family -- monitoring tools
Defensive programming skills
Select sorting and bubble sorting template
ctf-pikachu-CSRF
Sales management system of lightweight enterprises based on PHP
深入浅出对话系统——使用Transformer进行文本分类