Thursday, November 3, 2011

How to Upload Images outside of the Magento


define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';

umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);


Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(1);
$session = Mage::getSingleton('admin/session');
$session->setUser($userModel);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());


$product = Mage::getModel('catalog/product')
->loadByAttribute('sku','order');


$image = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'lamberts-logo.jpg';

$product->addImageToMediaGallery(Mage::getBaseDir('media') . DS .'l.jpg', array('image','thumbnail','small_image'), false, false);

try{
$product->save();

} catch(Exception $e){
echo $e->getMessage();
//handle your error
}
?>



Regards
Darshan Dodiya

No comments:

Post a Comment