I want to create custom module which can upload multiple images like product.I have created one custom module but it uploads only one image.
form.php
$fieldset->addField('filename', 'image', array(
'label' => Mage::helper('footertop')->__('File'),
'name' => 'filename',
));
I think you need to create your custom renderer for the image field. For this create this class in your module:
class [YOURNamespace]_[YOURModule]_Block_Adminhtml_[YOUREntity]_Helper_Image extends Varien_Data_Form_Element_Image{
//make your renderer allow "multiple" attribute
public function getHtmlAttributes(){
return array_merge(parent::getHtmlAttributes(), array('multiple'));
}
}
Now at the top of your _prepareForm (where you add your fields) add this line before adding any field:
$fieldset->addType('image', '[YOURNamespace]_[YOURModule]_Block_Adminhtml_[YOUREntity]_Helper_Image');
Or if you want to be "politically correct" add it this way:
$fieldset->addType('image', Mage::getConfig()->getBlockClassName('[YOURmodule]/adminhtml_[YOURentity]_helper_image'));
This will tell Magento that in your current fieldset, all the fields with type image should be rendered by your own class.
Now you can add your field like similar to how you did it:
$fieldset->addField('image', 'image', array(
'name' => 'image[]', //declare this as array. Otherwise only one image will be uploaded
'multiple' => 'multiple', //declare input as 'multiple'
'label' => Mage::helper('YOURmodule')->__('Select Image'),
'title' => Mage::helper('YOURmodule')->__('Can select multiple images'),
'required' => true,
'disabled' => $isElementDisabled
));
That's it. Don't forget to replace the placeholders ([YOURModule] and others) with your values.