php - Image import into magento -


i have bunch of images of products shop. now, don't want add images 1 one because time consuming. images' file names equal product name, tried this:

<?php require_once('app/mage.php');  umask(0); mage::app('default'); mage::app()->setcurrentstore(mage_core_model_app::admin_store_id);  $importdir = mage::getbasedir('media') . ds . 'import/'; $_productcollection = mage::getmodel('catalog/product')                ->getcollection()->addattributetoselect('*'); foreach($_productcollection $_product) {       $filename = $_product->getname();         $filepath = $importdir.$filename;          if ( file_exists($filepath) ) {         try {             $_product->addimagetomediagallery($filepath, 'image', false, false);             $_product->addimagetomediagallery($filepath, 'small_image', false, true);         } catch (exception $e) {             echo $e->getmessage();         }      }       $_product->save(); } ?> 

the code work if take 1 specific image, not work name. images inside import folder.

thanks!

you nave not mention extension of image (i.e., .jpg, .png, etc).

you have add extension $filepath

 $filepath = $importdir.$filename.'.png'; //if images png 

Comments