Question : Once Registered user upload custom image [custom image is Image which is uploaded by User ] in product view page & click on button "Save design" , we are creating Product Programatically . We want to upload that custom image to newly created product programatically.
Now we are using below code to upload existing image [ already saved image in server ] programatically.
protected function _createProduct($type, $doSave=true, $originalProduct) 
 {
 $product = Mage::getModel('catalog/product');
 // finally set custom data
 $product->setName($originalProduct->getName()); 
 // add product images
 $images = array(
 'thumbnail' => 'image.png',
 'small_image' => 'image.png',
 'image' => 'image.png',
 ); 
 $dir = Mage::getBaseDir('media') . DS . 'example/amasty/';
 foreach ($images as $imageType => $imageFileName) {
 $path = $dir . $imageFileName;
 if (file_exists($path)) {
 try {
 $product->addImageToMediaGallery($path, $imageType, false);
 } catch (Exception $e) {
 echo $e->getMessage();
 }
 } else {
 echo "Can not find image by path: `{$path}`<br/>";
 }
 }
 if ($doSave)
 $product->save();
 // To save inside my_designs
 $data = array('title'=>fav1_id,'product_id'=>$product->getId(),'customer_id'=> $customerId, 'value'=>image);
 $model = Mage::getModel('example/mydesign')->setData($data);
 try 
 {
 $fav1_id = $model->save()->getId();
 echo "Custom Design saved successfully";
 } catch (Exception $e)
 {
 echo $e->getMessage(); 
 }
 // To save inside my_designs end
 return $product;
 }
Sidenote : Once Registered user upload custom image in product view page & click on Add to cart, we are saving Custom image in Server in path : media/custom_options/quote and displaying image path in Table : sales_flat_quote_item_options
1 Answer 1
I think error in below line
instead of
 $dir = Mage::getBaseDir('media') . DS . 'example/amasty/';
Try below on
 $dir = Mage::getBaseDir('media') . DS . 'custom_options/quote/';
- 
 Hi plz come here once bro chat.stackexchange.com/rooms/55514/teja-bhagavanTeja Bhagavan Kollepara– Teja Bhagavan Kollepara2017年03月17日 04:24:00 +00:00Commented Mar 17, 2017 at 4:24
- 
 @TejabhagavanKollepara I dont have rights to message in that chatroom2017年03月17日 04:29:00 +00:00Commented Mar 17, 2017 at 4:29
- 
 check once now.Teja Bhagavan Kollepara– Teja Bhagavan Kollepara2017年03月17日 04:33:47 +00:00Commented Mar 17, 2017 at 4:33
- 
 @MurtuzaZabuawala Thanks, after click onsave designi need to upload custom image to theprogramtically created product, for that i need tosave custom image in server, but once i click onsave designcustom image is not saving in server.Baby in Magento– Baby in Magento2017年03月17日 05:14:07 +00:00Commented Mar 17, 2017 at 5:14
- 
 please checkeditpart in question......Baby in Magento– Baby in Magento2017年03月17日 06:53:28 +00:00Commented Mar 17, 2017 at 6:53
editpart in question......