@@ -52,7 +52,7 @@ public function init()
5252 throw new InvalidConfigException ('The uploadRoot is not defined correctly. ' );
5353 }
5454
55- $ this ->uploadRoot = trim ( trim ($ this ->uploadRoot , '/ ' ), '\\' );
55+ $ this ->uploadRoot = rtrim ( rtrim ($ this ->uploadRoot , '/ ' ), '\\' );
5656 }
5757
5858 /**
@@ -79,25 +79,23 @@ protected function getStorageType(): string
7979 */
8080 protected function setParamsForSend (): void
8181 {
82- $ uploadDir = trim ( trim ($ this ->getUploadDirConfig ($ this ->file ->type ), '/ ' ), '\\' );
82+ $ uploadDir = rtrim ( rtrim ($ this ->getUploadDirConfig ($ this ->file ->type ), '/ ' ), '\\' );
8383
8484 if (!empty ($ this ->subDir )) {
85- $ uploadDir = $ uploadDir .
86- DIRECTORY_SEPARATOR .
87- trim (trim ($ this ->subDir , '/ ' ), '\\' );
85+ $ uploadDir = $ uploadDir . DIRECTORY_SEPARATOR . trim (trim ($ this ->subDir , '/ ' ), '\\' );
8886 }
8987
9088 $ this ->uploadDir = $ uploadDir .
9189 DIRECTORY_SEPARATOR . substr (md5 (time ()), 0 , self ::DIR_LENGTH_FIRST ) .
9290 DIRECTORY_SEPARATOR . substr (md5 (microtime ().$ this ->file ->tempName ), 0 , self ::DIR_LENGTH_SECOND );
9391
94- $ this ->uploadPath = $ this ->uploadRoot . DIRECTORY_SEPARATOR . $ this ->uploadDir ;
92+ $ this ->uploadPath = $ this ->uploadRoot . DIRECTORY_SEPARATOR . ltrim ( ltrim ( $ this ->uploadDir , ' / ' ), '\\' ) ;
9593
9694 $ this ->outFileName = $ this ->renameFiles ?
9795 md5 (md5 (microtime ()).$ this ->file ->tempName ).'. ' .$ this ->file ->extension :
9896 Inflector::slug ($ this ->file ->baseName ).'. ' . $ this ->file ->extension ;
9997
100- $ this ->databaseUrl = DIRECTORY_SEPARATOR . $ this ->uploadDir . DIRECTORY_SEPARATOR . $ this ->outFileName ;
98+ $ this ->databaseUrl = $ this ->uploadDir . DIRECTORY_SEPARATOR . $ this ->outFileName ;
10199 }
102100
103101 /**
@@ -109,17 +107,11 @@ protected function setParamsForSend(): void
109107 */
110108 protected function setParamsForDelete (): void
111109 {
112- $ originalFile = pathinfo ($ this ->mediafileModel ->url );
113-
114- $ dirname = ltrim ($ originalFile ['dirname ' ], DIRECTORY_SEPARATOR );
110+ $ originalFile = pathinfo ($ this ->uploadRoot . DIRECTORY_SEPARATOR . ltrim (ltrim ($ this ->mediafileModel ->url , '\\' ), '/ ' ));
115111
116- $ dirnameParent = substr ($ dirname , 0 , -(self ::DIR_LENGTH_SECOND + 1 ));
112+ $ dirnameParent = substr ($ originalFile [ ' dirname ' ] , 0 , -(self ::DIR_LENGTH_SECOND + 1 ));
117113
118- if (count (BaseFileHelper::findDirectories ($ dirnameParent )) == 1 ) {
119- $ this ->directoryForDelete = $ this ->uploadRoot . DIRECTORY_SEPARATOR . $ dirnameParent ;
120- } else {
121- $ this ->directoryForDelete = $ this ->uploadRoot . DIRECTORY_SEPARATOR . $ dirname ;
122- }
114+ $ this ->directoryForDelete = count (BaseFileHelper::findDirectories ($ dirnameParent )) == 1 ? $ dirnameParent : $ originalFile ['dirname ' ];
123115 }
124116
125117 /**
@@ -160,19 +152,19 @@ protected function createThumb(ThumbConfigInterface $thumbConfig)
160152 $ originalFile = pathinfo ($ this ->mediafileModel ->url );
161153
162154 $ thumbUrl = $ originalFile ['dirname ' ] .
163- DIRECTORY_SEPARATOR .
164- $ this ->getThumbFilename ($ originalFile ['filename ' ],
165- $ originalFile ['extension ' ],
166- $ thumbConfig ->alias ,
167- $ thumbConfig ->width ,
168- $ thumbConfig ->height
169- );
170-
171- Image::thumbnail ($ this ->uploadRoot . DIRECTORY_SEPARATOR . $ this ->mediafileModel ->url ,
155+ DIRECTORY_SEPARATOR .
156+ $ this ->getThumbFilename ($ originalFile ['filename ' ],
157+ $ originalFile ['extension ' ],
158+ $ thumbConfig ->alias ,
159+ $ thumbConfig ->width ,
160+ $ thumbConfig ->height
161+ );
162+
163+ Image::thumbnail ($ this ->uploadRoot . DIRECTORY_SEPARATOR . ltrim ( ltrim ( $ this ->mediafileModel ->url , '\\' ), ' / ' ) ,
172164 $ thumbConfig ->width ,
173165 $ thumbConfig ->height ,
174166 $ thumbConfig ->mode
175- )->save ($ this ->uploadRoot . DIRECTORY_SEPARATOR . trim ( trim ($ thumbUrl , '\\' ), '/ ' ));
167+ )->save ($ this ->uploadRoot . DIRECTORY_SEPARATOR . ltrim ( ltrim ($ thumbUrl , '\\' ), '/ ' ));
176168
177169 return $ thumbUrl ;
178170 }
0 commit comments