Magento 2.1.6: Error filtering template: Unable to write file into directory

magento.stackexchange https://magento.stackexchange.com/questions/170657

  •  08-10-2020
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top