4

After upgrading from 2.1.5 to 2.1.6 CE. I'm getting below error on Windows WAMP while saving product on Admin side.

Unable to write file into directory \D:/wamp/www/magento/pub/media/catalog/product\cache\3cf5799449660ed39031217945ace72a/H/3. Access forbidden.

I tried below but it's for Linux

Access Denied (Permission Issue) after upgrade 2.0.3 -> 2.0.4

8

I just updated to Magento 2.1.6 on Windows and had this same issue. I did a little searching and came across a post on Github here.

In a nutshell you need to do two things in vendor/magento/module-catalog/Model/View/Asset/Image.php.

The first thing is replace all occurrences of DIRECTORY_SEPARATOR with '/'

The second is edit the getRelativePath function to look like:

private function getRelativePath($result)
{
    $prefix = $result == '/' ? $result : '';
    $result = $this->join($result, $this->getModule());
    $result = $this->join($result, $this->getMiscPath());
    $result = $this->join($result, $this->getFilePath());
    return $prefix . $result;
}

You need both changes or it won't work. Just replacing DIRECTORY_SEPARATOR still throws a forbidden error. Not including the $prefix elements in getRelativePath causes the forbidden error to go away, but product images won't load.

  • In magento2.1.7 there is not any such file (vendor/magento/module-catalog/Model/View/Asset/Image.php) and I'm having the same issue. What should I do? – saiid Dec 28 '17 at 10:44
2

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.

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.