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

Description: After installation of magento 2 with sample data, If you see above error then you can solve this issue with following way.

Go to your project directory : 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.

Advertisements