0

after install Magento 2.1.6 on Windows 10 XAMPP I got this error in the frontend homepage:

Error filtering template: Unable to write file into directory \C:/xampp/htdocs/Magento/pub/media/catalog/product\cache\f073062f50e48eb0f0998593e568d857/m/b. Access forbidden.

I google it but I did not find any answer how to fix it.

2
  • make sure you have write access to the pub/media folder.
    – Marius
    Apr 18 '17 at 18:04
  • @Marius I have the complete access to the folder
    – Albydaz
    Apr 19 '17 at 22:20
0

There is a simple way to solve this issue: in vendor/magento/module-catalog/Model/View/Asset/Image.php:226 remove the 'DIRECTORY_SEPARATOR'

private function getRelativePath($result)
{
$result = $this->join($result, $this->getModule());
$result = $this->join($result, $this->getMiscPath());
$result = $this->join($result, $this->getFilePath());
return $result;
}

and: /vendor/magento/module-catalog/Model/View/Asset/Image.php:130 replace DIRECTORY_SEPARATOR to '/'

 private function join($path, $item)
    {
        return trim(
            $path . ($item ? '/' . ltrim($item, '/') : ''),
            '/'
        );
    }

PHP accepts both \ and / as valid path separators. So just use / in your code.

1
  • Hello @jitendra kumar, thank you very much for your answer. I also made the second change at line 130 and I am now able to view all the sample images in the frontend and in the backend thunmnail.
    – Albydaz
    Apr 29 '17 at 15:48
0

There is a "DIRECTORY_SEPARATOR" issue in your path.

open vendor/magento/module-catalog/Model/View/Asset/Image.php. Go to lie number 226 and remove the 'DIRECTORY_SEPARATOR'

private function getRelativePath($result)
{
$result = $this->join($result, $this->getModule());
$result = $this->join($result, $this->getMiscPath());
$result = $this->join($result, $this->getFilePath());
return $result;
}
5
  • Hi @Amitkumar solanki, I have removed the 'DIRECTORY_SEPARATOR' in line 231 but I still have the error in the homepage. Thanks
    – Albydaz
    Apr 19 '17 at 22:22
  • @Albydaz, Please clear cache and run php bin/magento setup:static-content:deploy. I got same error and resolved it. Apr 20 '17 at 5:26
  • After removing the 'DIRECTORY_SEPARATOR' in line 231, clear all cache folders from var/cache and run php bin/magento setup:static-content:deploy the error is still in the homepage: Error filtering template: Unable to write file into directory \C:/xampp/htdocs/Magento/pub/media/catalog/product\cache\f073062f50e48eb0f0998593e568d857\/m/b. Access forbidden.
    – Albydaz
    Apr 20 '17 at 19:37
  • Hello Albydaz, contact me on skype with my skype id developer_amit_php, we will resolve it. Apr 21 '17 at 5:58
  • I started Magento this morning and the error was gone. I can see images in the frontpage now. Thank you for your help!
    – Albydaz
    Apr 23 '17 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.