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.

Jackson
  • 9,909
  • 29
  • 128
  • 217
Albydaz
  • 3
  • 2

2 Answers2

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;
}
Amitkumar solanki
  • 875
  • 1
  • 7
  • 20
  • 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. – Amitkumar solanki Apr 20 '17 at 05: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. – Amitkumar solanki Apr 21 '17 at 05: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
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.

Jitendra Mohanta
  • 642
  • 8
  • 18
  • 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