@@ -165,7 +165,7 @@ protected function getFilename(UploadedFile $file, array $config)
165
165
166
166
$ filename = config ('ueditor.hash_filename ' ) ? md5 ($ file ->getFilename ()).$ ext : $ file ->getClientOriginalName ();
167
167
168
- return str_finish ( $ this ->formatPath ($ config ['path_format ' ]), ' / ' ). $ filename ;
168
+ return $ this ->formatPath ($ config ['path_format ' ], $ filename) ;
169
169
}
170
170
171
171
/**
@@ -218,23 +218,27 @@ protected function error($message)
218
218
* Format the storage path.
219
219
*
220
220
* @param string $path
221
+ * @param string $filename
221
222
*
222
223
* @return mixed
223
224
*/
224
- protected function formatPath ($ path )
225
+ protected function formatPath ($ path, $ filename )
225
226
{
226
227
$ time = time ();
227
228
$ 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 );
231
231
232
232
//替换随机字符串
233
233
if (preg_match ('/\{rand\:([\d]*)\}/i ' , $ path , $ matches )) {
234
234
$ length = min ($ matches [1 ], strlen (PHP_INT_MAX ));
235
235
$ path = preg_replace ('/\{rand\:[\d]*\}/i ' , str_pad (mt_rand (0 , pow (10 , $ length ) - 1 ), $ length , '0 ' , STR_PAD_LEFT ), $ path );
236
236
}
237
237
238
+ if (!str_contains ($ path , $ filename )) {
239
+ $ path = str_finish ($ path , '/ ' ).$ filename ;
240
+ }
241
+
238
242
return $ path ;
239
243
}
240
244
}
0 commit comments