Skip to content
This repository was archived by the owner on Aug 22, 2021. It is now read-only.

Commit f637eac

Browse files
committed
Support '{filename}'.overtrue#19
1 parent a9f5a94 commit f637eac

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/StorageManager.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected function getFilename(UploadedFile $file, array $config)
165165

166166
$filename = config('ueditor.hash_filename') ? md5($file->getFilename()).$ext : $file->getClientOriginalName();
167167

168-
return str_finish($this->formatPath($config['path_format']), '/').$filename;
168+
return $this->formatPath($config['path_format'], $filename);
169169
}
170170

171171
/**
@@ -218,23 +218,27 @@ protected function error($message)
218218
* Format the storage path.
219219
*
220220
* @param string $path
221+
* @param string $filename
221222
*
222223
* @return mixed
223224
*/
224-
protected function formatPath($path)
225+
protected function formatPath($path, $filename)
225226
{
226227
$time = time();
227228
$partials = explode('-', date('Y-y-m-d-H-i-s'));
228-
$replacement = ['{yyyy}', '{yy}', '{mm}', '{dd}', '{hh}', '{ii}', '{ss}'];
229-
$path = str_replace($replacement, $partials, $path);
230-
$path = str_replace('{time}', $time, $path);
229+
$replacement = ['{yyyy}', '{yy}', '{mm}', '{dd}', '{hh}', '{ii}', '{ss}', '{filename}', '{time}'];
230+
$path = str_replace($replacement, array_merge($partials, [$filename, $time]), $path);
231231

232232
//替换随机字符串
233233
if (preg_match('/\{rand\:([\d]*)\}/i', $path, $matches)) {
234234
$length = min($matches[1], strlen(PHP_INT_MAX));
235235
$path = preg_replace('/\{rand\:[\d]*\}/i', str_pad(mt_rand(0, pow(10, $length) - 1), $length, '0', STR_PAD_LEFT), $path);
236236
}
237237

238+
if (!str_contains($path, $filename)) {
239+
$path = str_finish($path, '/').$filename;
240+
}
241+
238242
return $path;
239243
}
240244
}

0 commit comments

Comments
 (0)