I hase used this code :
require_once("app/Mage.php");
Mage::app();
$fullImagePath = "app/code/local/Mycompany/Import/data/images/test_picture.jpg";
$product = Mage::getModel('catalog/product');
$product->load(16);
$product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
$product->addImageToMediaGallery ($fullImagePath, array ('image'), false, false);
$product->save();
to import pictures to a product.
开发者_JS百科The problem in that is that when I delete the programmatically imported picture from the backend, it stay always visible in frontend.
I don't know what's wrong in my code.
Thanks for help.
I think in your import code instead of doing setMediaGallery() and hard coding your image url you should,
$config = $product->getMediaConfig();
//and get your file url from the set media path in your config.
$fileurl = $config->getMediaUrl('sth/test_picture.jpg');
精彩评论