当前位置:网站首页>laravel admin里百度编辑器自定义路径和文件名
laravel admin里百度编辑器自定义路径和文件名
2022-07-04 03:47:00 【king2wang】
最近遇见一个问题,从word里复制图片粘贴到后台富文本框里,保存后图片老是被覆盖,后来发现是由于百度编辑器默认保存的时候是使用源文件的文件名md5()后当文件名,而从word里复制的图片,文件名默认都是一样的,所以导致了图片覆盖的情况,所以决定自定义路径和文件名。。。。
1.自定义路径
这个很简单,找到config/ueditor.php,找到imagePathFormat进行修改即可,还有其他情况下上传路径,需要的话都可以对应修改,包括(scrawlPathFormat、snapscreenPathFormat、catcherPathFormat、filePathFormat等)

2.自定义文件名,这个就稍微麻烦一点了,因为没有直接的配置,只能修改源代码,
源码位置:vendor/codingyu/laravel-ueditor/src/StorageManager.php
找到getFilename()方法
原来的代码是:获取源文件的名字后进行根据ueditor.hash_filename配置进行md5()加密或不加密,但不管是否加密只要源文件名字是一样的,那么就会出现文件被覆盖的情况。
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);
}修改后的代码:鉴于这种情况,我们就可以使用自定义文件名的方式,这里依然延续之前的逻辑,当ueditor.hash_filename=true的时候再自定义名字(这里使用的是时间戳加随机字符串),否则就使用源文件名
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);
}到此,大功告成~
边栏推荐
- Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
- AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
- Pytest multi process / multi thread execution test case
- Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
- 疫情来袭--远程办公之思考|社区征文
- Katalon framework tests web (XXI) to obtain element attribute assertions
- Webhook triggers Jenkins for sonar detection
- static hostname; transient hostname; pretty hostname
- Zigzag scan
- Zlmediakit compilation and webrtc push-pull flow testing
猜你喜欢

GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day

三年进账35.31亿,这个江西老表要IPO了

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

Objective-C description method and type method

Typical applications of minimum spanning tree

如何有效远程办公之我见 | 社区征文

微信公众号网页授权

Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!

拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。

Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
随机推荐
postgresql 用户不能自己创建表格配置
MySQL maxscale realizes read-write separation
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
Mindmanager2022 efficient and easy to use office mind map MindManager
三年进账35.31亿,这个江西老表要IPO了
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Es network layer
用于TCP协议交互的TCPClientDemo
Select sorting and bubble sorting template
'2'>' 10'==true? How does JS perform implicit type conversion?
Katalon框架测试web(二十六)自动发邮件
Package details_ Four access control characters_ Two details of protected
Explain AI accelerator in detail: why is this the golden age of AI accelerator?
[book club issue 13] multimedia processing tool ffmpeg tool set
What are the virtual machine software? What are their respective functions?
Why is it recommended that technologists write blogs?
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
Spa in SDP
Object oriented -- encapsulation, inheritance, polymorphism