@@ -76,7 +76,7 @@ private function getMediaDirectory()
7676 private function getBaseDirectory ()
7777 {
7878 if (!isset ($ this ->baseDirectory )) {
79- $ this ->baseDirectory = $ this ->filesystem ->getDirectoryRead (DirectoryList::PUB );
79+ $ this ->baseDirectory = $ this ->filesystem ->getDirectoryRead (DirectoryList::ROOT );
8080 }
8181
8282 return $ this ->baseDirectory ;
@@ -135,7 +135,7 @@ private function getFilePath($fileName)
135135 {
136136 $ filePath = ltrim ($ fileName , '/ ' );
137137
138- $ mediaDirectoryRelativeSubpath = $ this ->getMediaDirectoryPathRelativeToBaseDirectoryPath ();
138+ $ mediaDirectoryRelativeSubpath = $ this ->getMediaDirectoryPathRelativeToBaseDirectoryPath ($ filePath );
139139 $ isFileNameBeginsWithMediaDirectoryPath = $ this ->isBeginsWithMediaDirectoryPath ($ fileName );
140140
141141 // if the file is not using a relative path, it resides in the catalog/category media directory
@@ -160,7 +160,7 @@ public function isBeginsWithMediaDirectoryPath($fileName)
160160 {
161161 $ filePath = ltrim ($ fileName , '/ ' );
162162
163- $ mediaDirectoryRelativeSubpath = $ this ->getMediaDirectoryPathRelativeToBaseDirectoryPath ();
163+ $ mediaDirectoryRelativeSubpath = $ this ->getMediaDirectoryPathRelativeToBaseDirectoryPath ($ filePath );
164164 $ isFileNameBeginsWithMediaDirectoryPath = strpos ($ filePath , $ mediaDirectoryRelativeSubpath ) === 0 ;
165165
166166 return $ isFileNameBeginsWithMediaDirectoryPath ;
@@ -169,14 +169,20 @@ public function isBeginsWithMediaDirectoryPath($fileName)
169169 /**
170170 * Get media directory subpath relative to base directory path
171171 *
172+ * @param string $filePath
172173 * @return string
173174 */
174- private function getMediaDirectoryPathRelativeToBaseDirectoryPath ()
175+ private function getMediaDirectoryPathRelativeToBaseDirectoryPath (string $ filePath = '' )
175176 {
176177 $ baseDirectoryPath = $ this ->getBaseDirectory ()->getAbsolutePath ();
177178 $ mediaDirectoryPath = $ this ->getMediaDirectory ()->getAbsolutePath ();
178179
179180 $ mediaDirectoryRelativeSubpath = substr ($ mediaDirectoryPath , strlen ($ baseDirectoryPath ));
181+ $ pubDirectory = 'pub/ ' ;
182+
183+ if (strpos ($ mediaDirectoryRelativeSubpath , $ pubDirectory ) === 0 && strpos ($ filePath , $ pubDirectory ) !== 0 ) {
184+ $ mediaDirectoryRelativeSubpath = substr ($ mediaDirectoryRelativeSubpath , strlen ($ pubDirectory ));
185+ }
180186
181187 return $ mediaDirectoryRelativeSubpath ;
182188 }
0 commit comments