I created a form to add products in the frontend, and I've added products with all attributes, except for product image. When I save, it shows: Image does not exist. Please help me find the problem. Thanks.

My template:

<div class="field name-image">
    <label class="required"><em>*</em><?php echo $this->__('Image') ?></label>
    <div class="input-box">
        <input type="file" id="<?php echo $this->getFieldId('image')?>" name="image title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('image')) ?>" />

In controller:

 $product = new Mage_Catalog_Model_Product();

 $filename = $_FILES['image']['name'];
 $image = Mage::getBaseDir('media') . DS . "catalog\product" . DS . $filename;
 $product ->setMediaGallery(array('images' => array(), 'values' => array()))
            ->addImageToMediaGallery($image, array('image', 'small_image', 'thumbnail'), false, false);

1 Answer 1


You need to do code like this.

$path = '';

if(isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') 
        $uploader = new Varien_File_Uploader('image');

        $path = Mage::getBaseDir(‘media’) . DS . "catalog\product" . DS ;
        $uploader->save($path, $_FILES[‘image’][‘name’] );
     catch (Exception $e) 


     $newpath = $path.$_FILES[‘image’][‘name’];
     $product->addImageToMediaGallery($newpath, array('image', 'thumbnail', 'small_image'), false, false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.