I need to get product image path with raw sql. Where does Magento store product image cache path? Table catalog_product_entity_media_gallery stores images but without the cache path (/2/0/20.jpg).

  • let me know the magento version please Aug 23, 2017 at 4:19

2 Answers 2


You can try this:

$product = Mage::getModel('catalog/product')->load($product_id);
$thumbnailpath = Mage::helper('catalog/image')->init($product, 'thumbnail');
$bigImagepath = Mage::helper('catalog/image')->init($product, 'image');
$smallImagepath = Mage::helper('catalog/image')->init($product, 'small_image');

Check also this post: https://magento.stackexchange.com/a/1008/7781

  • I can not use Magento models, I need raw sql.
    – JohnyFree
    Feb 3, 2016 at 8:35
  • You have no way to do that. Because the path is constructed "dinamically" Read this, please: magento.stackexchange.com/a/1008
    – osrecio
    Feb 3, 2016 at 8:52

The URL of images in cache is complex because it contains the MD5 of image params.(example: /media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/m/e/me-d1_2.jpg)

But you can easily get the original image URL.

To get the base URL (unsecure):

SELECT value FROM core_config_data WHERE path='web/unsecure/base_url'

If you want the secure URL:

SELECT value FROM core_config_data WHERE path='web/secure/base_url'

it returns the website URL.

To construct the image URL, add "media/catalog/product" and the image path (example: "/a/c/ace-furniture.jpg").



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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