Hello,
I'm having a rather strange issue with Magento 2. I pulled a full copy of the site to my local dev, did some styling and content changes, nothing major, then migrated the site from my local back to the server, and for some reason, several but not all of the product images are missing.
I've had this issue with another site for a different client, but also a Magento 2 site, hosted in another SiteGround account.
To move the sites I:
- export the database (I've tried both with mysqldump command line and PHPMyAdmin)
- compress the entire site directory (I tried zip and tar)
- copy both files to or from the server using SSH scp command
- edit the env.php file with the corresponding local or remote DB info
- edit the core_config_data entries with corresponding local or remote domains
- clear cache and re-deploy static content
I've also tried to rsync the entire site with the same results.
Thank you for your advice.
Solved! Go to Solution.
The issue was related to the pub/media/catalog/product subdirectories case. Magento store product images in subdirectories that use the 1st and 2nd letter of the image filename, for example, a product which image file name is sticker.jpg is stored in pub/media/catalog/product/s/t/sticker.jpg.
The issue started when cloning the site to a local Mac OS dev environment, then cloned back to the server. Some directory names where in upper case and some not, and for some reason, the links to the product images which directory started with upper case were lost.
I fixed the issue by changing all letter directories to lowercase, then changing the image path to lower case as well in the corresponding database tables:
UPDATE catalog_product_entity_media_gallery SET value = CONCAT(LCASE(LEFT(value,4)),SUBSTRING(value, 5, CHAR_LENGTH(value)))
UPDATE `catalog_product_entity_varchar` SET value = CONCAT(LCASE(LEFT(value,4)),SUBSTRING(value, 5, CHAR_LENGTH(value))) WHERE value LIKE '/%'
I hope this helps somebody some time.
The issue was related to the pub/media/catalog/product subdirectories case. Magento store product images in subdirectories that use the 1st and 2nd letter of the image filename, for example, a product which image file name is sticker.jpg is stored in pub/media/catalog/product/s/t/sticker.jpg.
The issue started when cloning the site to a local Mac OS dev environment, then cloned back to the server. Some directory names where in upper case and some not, and for some reason, the links to the product images which directory started with upper case were lost.
I fixed the issue by changing all letter directories to lowercase, then changing the image path to lower case as well in the corresponding database tables:
UPDATE catalog_product_entity_media_gallery SET value = CONCAT(LCASE(LEFT(value,4)),SUBSTRING(value, 5, CHAR_LENGTH(value)))
UPDATE `catalog_product_entity_varchar` SET value = CONCAT(LCASE(LEFT(value,4)),SUBSTRING(value, 5, CHAR_LENGTH(value))) WHERE value LIKE '/%'
I hope this helps somebody some time.
You, sir or ma'am, are a saint! This was exactly my issue and your fix worked beautifully. Strange issue. I noticed that one of my folders had a capital when navigating the folder structure but didn't pay attention to it. We have a third party dev working on our site and I assume somewhere along the line the site/code lived on MacOS.
Thank you so much for taking the time to come back to your own post to provide the answer!
Hey, I'm glad I helped. Magento 2 is full of surprises like this so it helps to document and share bits like this.
Worked well for Magento 1.9 , too.
Great answer.
I have similar if not same situation and I have got folders with c and C, s and S etc. DId you move files and subfolders from C to c. I guess it is not possible to have 2 c or two s folders.
@vedran_vucic wrote:I have similar if not same situation and I have got folders with c and C, s and S etc. DId you move files and subfolders from C to c. I guess it is not possible to have 2 c or two s folders.
As I mentioned in the solution:
"I fixed the issue by changing all letter directories to lowercase"
Rather than moving files around, I simply renamed all uppercase directory names to lower case, then did the query to do the same on the database.
Absolute genius, this worked for me
Thank you SO much. Your post has solved an issue I've been wrestling with all afternoon! Legend!