Image Resizer doesn't work when Winter CMS is installed in a subdirectory #213
-
Description:When Winter is installed as a subdirectory and you try to use resizer to resize images in your theme or component, you get a 404 because it tries to find the URL /resizer/d2...cf1/%252Fstorage%252Fapp%252.... Steps To Reproduce:
Suggested Fix:I identified that in public function getResizerUrl (line ~502) /**
* Get the URL to the system resizer route for this instance's configuration
*
* @return string $url
*/
public function getResizerUrl()
{
// Slashes in URL params have to be double encoded to survive Laravel's router
// @see https://github.com/octobercms/october/issues/3592#issuecomment-671017380
$resizedUrl = rawurlencode(rawurlencode($this->getResizedUrl()));
// Get the current configuration's identifier
$identifier = $this->getIdentifier();
// Store the current configuration
$this->storeConfig();
// IF YOU ADD THE CONFIG::GET APP.URL IT WORKS
$url = Config::get('app.url','')."/resizer/$identifier/$resizedUrl";
if (Config::get('cms.linkPolicy', 'detect') === 'force') {
$url = Url::to($url);
}
return $url;
}
/**
* Get the URL to the resized image
*
* @return string
*/
public function getResizedUrl()
{
$url = '';
if ($this->image['source'] === 'filemodel') {
$model = $this->getFileModel();
$thumbFile = $model->getThumbFilename($this->width, $this->height, $this->options);
$url = $model->getPath($thumbFile);
} else {
$resizedDisk = Storage::disk(Config::get('cms.storage.resized.disk', 'local'));
$url = $resizedDisk->url($this->getPathToResizedImage());
}
// Ensure that a properly encoded URL is returned
$segments = explode('/', $url);
$lastSegment = array_pop($segments);
// AGAIN HERE - ADDING THE APPURL WORKS TOO
$url = Config::get('app.url','').implode('/', $segments) . '/' . rawurlencode(rawurldecode($lastSegment));
if (Config::get('cms.linkPolicy', 'detect') === 'force') {
$url = Url::to($url);
}
return $url;
} |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Thanks @bugzbrown. Would you be willing to put this in a PR for us? |
Beta Was this translation helpful? Give feedback.
-
@bugzbrown @bennothommo Actually this may not be the issue because situations like this are documented in Line 303 in 4f95310 |
Beta Was this translation helpful? Give feedback.
-
@bugzbrown you should be able to either add the subfolder to the path or set a linkPolicy of force and it should work. Give that a try and report back please. |
Beta Was this translation helpful? Give feedback.
-
In my opinion this may be closed or at least "bug" label should be replaced with something else if there are plans to improve this in future. Currently this can be fixed by adjusting config file. |
Beta Was this translation helpful? Give feedback.
-
See Lines 303 to 306 in 4f95310 |
Beta Was this translation helpful? Give feedback.
See
winter/config/cms.php
Lines 303 to 306 in 4f95310