Magento 2 – Unable to Write File into Directory, Access Forbidden

adminmagento2magento2.1.6wampwindows

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

Best Answer

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.