Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to get the path of the image’s folder
 
CM03
Member
 
Total Posts:  67
Joined:  2007-11-22
 

Hi,

I need to use the path of the folder which contains the images of a product.

I find how to get the complete url of an image but I need only the path of the folder (without the image’s filename).

For example the complete url is : http://127.0.0.1/magento/media/catalog/product/cache/1/image/5e06319eda06f020e43594a9c230972d/t/e/tee-shirt-col-v-ml-vert.jpg ==> $this->helper(’catalog/image’)->init($_product, ‘image’)

And I want just the path whitout the last filename : http://127.0.0.1/magento/media/catalog/product/cache/1/image/5e06319eda06f020e43594a9c230972d/t/e/

Please can you help me ?

Thanks a lot !!

 
Magento Community Magento Community
Magento Community
Magento Community
 
BBrizzio
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2008-05-19
salò, Brescia, Italy
 

I don’t know how to get image path correctly (using magento libraries).

I’ve solved my problem using regular expressions:

$imageurl=Mage::helper('catalog/image')->init($product'image');
  
$newimageurl=preg_replace("|/cache/[0-9a-z]*/image/[0-9a-z]*|i","",$imageurl);
   if (
$newimageurl{
    $rr[
'image_url']=$newimageurl;
   
else {
    $rr[
'image_url']=$imageurl;
   
}

Hope this helps you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
CM03
Member
 
Total Posts:  67
Joined:  2007-11-22
 

Thanks a lot for your answer BBrizzio !

To get only the path without the filename, we can add the last line at your code :

$imageurl=Mage::helper('catalog/image')->init($product'image');
  
$newimageurl=preg_replace("|/cache/[0-9a-z]*/image/[0-9a-z]*|i","",$imageurl);
   if (
$newimageurl{
    $rr[
'image_url']=$newimageurl;
   
else {
    $rr[
'image_url']=$imageurl;
   

$justpath
=dirname($rr['image_url']);
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top