I have a CI project and a Magento Project on same server.

I want to periodically import Magento products into my CI website.

Everything is working perfectly, I am currently able to import each thing from Magento to my CI website.

BUT, how do I get physical/server paths of images of magento product? I want to copy those image files to my CI project.

Here is relative line I am loading product with

$product = $simpleProduct->getData()

And this is Image related part of what I get in return. look at file key, its not actual server path.



PS I dont want browser path of an image like this http://www.website/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/2/-/image_name_here.jpg

I want server path.

1 Answer 1


AFAIK, there is no clean way of doing it out of the box.

The hacky script I tend to use is the following (note that $file corresponds to the data stored with the file key in your media gallery images array):

$imageUrl = Mage::helper('catalog/image')->init($_product, 'image', $file)->__toString();
$imagePath = str_replace(array(Mage::getBaseUrl('media'), '/'), array(Mage::getBaseDir('media').DS, DS), $imageUrl);

Pretty sure I found it on StackExchange a while ago but can't get my hands on the link.

  • ` $_product = $simpleProduct->load($_GET['loadprod']); foreach ($simpleProduct->getMediaGalleryImages() as $image) { $imageUrl = Mage::helper('catalog/image')->init($simpleProduct, 'image', $image)->__toString(); echo $imagePath = str_replace(array(Mage::getBaseUrl('media'), '/'), array(Mage::getBaseDir('media') . DS, DS), $imageUrl); }` returned me link like website.com/test/skin/frontend/default/kawaii/images/catalog/…
    – Umair Ayub
    Oct 28, 2016 at 9:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.