I don't think it's necessary to check catalog_product_entity_varchar
first. Image "names" are stored in catalog_product_entity_media_gallery
table, but the DB value already contains subfolder prefixes:
So for your product_image.png
the entry is /p/r/product_image.png
.
Raw SQL for filename ad location could look like:
SELECT
SUBSTRING(value, 6) as 'file',
CONCAT('your_magento_url/media/catalog/product', value) as 'path'
FROM catalog_product_entity_media_gallery;
... or for php script ...
$path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog' . DS . 'product';
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('core_read');
$query = $read->select()
->from($resource->getTableName('catalog_product_entity_media_gallery'), array('file', 'path'))
->reset(Zend_Db_Select::COLUMNS)
->columns('SUBSTRING(value, 6) as file')
->columns('CONCAT("' . $path . '", value) as path');
$images = $read->fetchPairs($query);
This would give you an array like
array(
'product_image.png' => 'full/path/to/product_image.png',
...
);