@@ -77,15 +77,14 @@ public static function factory($config = [], $class = FileAPI::class)
77
77
*/
78
78
protected function callback (UploadedFile $ uploadedFile , $ path , $ domain )
79
79
{
80
- $ clientOriginalName = $ uploadedFile ->getClientOriginalName ();
81
- $ clientOriginalExtension = strtolower ($ uploadedFile ->getClientOriginalExtension ());
82
- $ basename = pathinfo ($ uploadedFile ->getBasename (), PATHINFO_FILENAME );
83
- $ filename = md5 ($ basename ).'. ' .$ clientOriginalExtension ;
80
+ $ clientPathInfo = $ this ->pathInfo ($ uploadedFile ->getClientOriginalName ());
81
+ $ basePathInfo = $ this ->pathInfo ($ uploadedFile ->getBasename ());
82
+ $ filename = md5 ($ basePathInfo ['basename ' ]).'. ' .$ clientPathInfo ['extension ' ];
84
83
$ mimeType = $ uploadedFile ->getMimeType ();
85
84
$ size = $ uploadedFile ->getSize ();
86
85
$ uploadedFile ->move ($ path , $ filename );
87
86
$ response = [
88
- 'name ' => pathinfo ( $ clientOriginalName , PATHINFO_FILENAME ) .'. ' .$ clientOriginalExtension ,
87
+ 'name ' => $ clientPathInfo [ ' filename ' ] .'. ' .$ clientPathInfo [ ' extension ' ] ,
89
88
'tmp_name ' => $ path .$ filename ,
90
89
'type ' => $ mimeType ,
91
90
'size ' => $ size ,
@@ -94,4 +93,15 @@ protected function callback(UploadedFile $uploadedFile, $path, $domain)
94
93
95
94
return new JsonResponse ($ response );
96
95
}
96
+
97
+ private function pathInfo ($ path )
98
+ {
99
+ $ parts = [];
100
+ $ parts ['dirname ' ] = rtrim (substr ($ path , 0 , strrpos ($ path , '/ ' )), '/ ' ).'/ ' ;
101
+ $ parts ['basename ' ] = ltrim (substr ($ path , strrpos ($ path , '/ ' )), '/ ' );
102
+ $ parts ['extension ' ] = strtolower (substr (strrchr ($ path , '. ' ), 1 ));
103
+ $ parts ['filename ' ] = ltrim (substr ($ parts ['basename ' ], 0 , strrpos ($ parts ['basename ' ], '. ' )), '/ ' );
104
+
105
+ return $ parts ;
106
+ }
97
107
}
0 commit comments