Magento2: [Urgent]Big Problem in Magento 2.1.6 Can't Create Re-size Image In Window 7 - Xampp

Created on 12 Apr 2017  路  20Comments  路  Source: magento/magento2

Hi Everyone,
I just Updated my site to Magento 2.1.6 in local but I have the problem with image re-size.
Here my issue when I turn on the "Developer" Mode

Error filtering template: Unable to write file into directory \D:/xampp/htdocs/mag2/ce216/mysite/pub/media/catalog/product\cache\2eaddfd0be171511b8beb7c8a6c1c63e\/c/v. Access forbidden.

I'm tried to clean all var and pub folder but not a success.

I'm using the Window 7 and Xampp Server.
Please help me resolved this issue.

Best Regards,
Ziven.

needs update

Most helpful comment

Try this

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;
}

And You can replace all DIRECTORY_SEPARATOR to '/' in this file.

All 20 comments

Magento does not support the operating system you've listed. Please confirm that you can reproduce this issue on a supported platform. For an overview of supported technologies, see System Requirements.

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 '/'

PHP accepts both \ and / as valid path separators in all OS. So just use / in your code.

Hi I have similar problems. If I change the code according to Hoszi then all non-product images are shown correctly but the product images are not because in the image URL 'product/cache' is changed to 'productcache'. I think this is because of the removal of the DIRECTORY_SEPARATOR. If I add it back again then the produt URLs are fine but then the non-product images are wrong (because of 2 // in the URL). So Hoszi can you explain some more maybe? Thx.

Try this

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;
}

And You can replace all DIRECTORY_SEPARATOR to '/' in this file.

This did the trick Hoszi thanks a lot :)

Still my all product images are not loading. All Product images are showing 404

@sanjayjethva You need to do both of the suggestions from @Hoszi.

In vendor/magento/module-catalog/Model/View/Asset/Image.php:

  • replace all DIRECTORY_SEPARATOR with '/'

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;
}

I had the same issue and played around with it some to see if both changes were needed. If you just replace DIRECTORY_SEPARATOR then the file paths are still broken and you get the forbidden access error. If you just add the $prefix parts to getRelativePath then the forbidden access error goes away but all the product images will 404.

In 2.1.6 CE Below Works for Me

private function join($path, $item)
{
   return trim($path . ($item ? '/' . ltrim($item, '/') : ''),'/');
}

private function getRelativePath($result)
{
    $result = $this->join($result, $this->getModule());
    $result = $this->join($result, $this->getMiscPath());
    $result = $this->join($result, $this->getFilePath());
    return $result;
}

Hi @mikelevy300
Thanks for your answer.
Actually all product cache images were broken and unable to load.
Can you please tell me how can i resolve that?

Thanks

I fixed this issue by removing DIRECTORY_SEPARATOR as below
private function getRelativePath($result)
{
$result = $this->join($result, $this->getModule());
$result = $this->join($result, $this->getMiscPath());
$result = $this->join($result, $this->getFilePath());
return $result;
}
in the file app/code/Magento/Catalog/Model/View/Asset/Image.php:226

Did you just edit core files?

How can I overwrite the app/code/Magento/Catalog/Model/View/Asset/Image.php in my custom theme?

I have the same issue, at Debian 8(Apache2.4+php5.6),
I updated from Ver2.1.5 to Ver2.1.6 then all product images in the category list page are 404.
I tried the following command and it solved it.

$ ./bin/magento catalog:images:resize

To those in the same isue. How is that?

Confirmed! We get the same issue when installing Magento 2.1.6 sample data in localhost (Windows 10 + XAMPP)

@vpelipenko: Any solutions to resolved?
Please help us.
Best Regards,
Ziven.

I have some guys to help and tell me like this:
"I have installed Cygwin on Windows 7 and use chmod in such cases. It solves this problem."
I think this is one solution to resolve this issue for this time.

Hi there,
I've got the same issue, and tried to edit the Image.php as you guys suggested and returns this error instead.
Fatal error: Namespace declaration statement has to be the very first statement in the script in C:\wamp64\www\magento\vendor\magento\module-catalog\Model\View\Asset\Image.php on line 2
In my Image.php file:

<?php
namespace Magento\Catalog\Model\View\Asset;

There are some people facing this error too, and other said it might be there is a hidden/blank space between the namespace and php opening tag, but there isn't.
Please somebody kindly help me solve this.

It seems this might be fixed with #9492 can you please try the suggested solution and report back?

Magento just released 2.1.7 with a "reversion of the changes to image resizing that we introduced in 2.1.6": http://devdocs.magento.com/guides/v2.1/release-notes/ReleaseNotes2.1.7CE.html

Can you please check if the problem is gone in 2.1.7? Thanks!

Well. It fixed in Magento 2.1.7.

Thanks for fixing.
I installed 2.1.7 with sample data and I got into issue , once I run bin/magento catalog:images:resize it solved it .
But I was on Ubuntu but this helped.

Was this page helpful?
0 / 5 - 0 ratings