1

I'm trying add image to product gallery by downloading image file from internet to my magento server and add this as main image in gallery by addImageToMediaGallery method:

                $imageToAdd = 'http://example.com/some_image.jpg';
                $uploadedImgsDir = Mage::getBaseDir('media') . '/uploaded-imgs';
                $imageFilePathForUpload = $uploadedImgsDir . '/' . (new SplFileInfo($imageToAdd))->getFilename();
                file_put_contents($imageFilePathForUpload, fopen($imageToAdd, 'r'));
                // Add Image to Gallery
                $imgCfg = ['image', 'small_image', 'thumbnail'];
                $product->addImageToMediaGallery($imageFilePathForUpload, $imgCfg, false, false);

However, In product gallery in I see my image (with url = http://example-magento.com/image1.jpg) with 'image', 'small_image', 'thumbnail' = false and other image (with 404 url - with _1 adition in url - = http://example-magento.com/image1_1.jpg):

enter image description here

Please help (any idea would be appreciated). Or Please request more information I'll add them in my question.

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.