For upload multiple files, first we have to change input type in Abstract.php
go to lib/Varien/Data/Form/Element/Abstract.php
look for function and replace
public function getElementHtml()
{
if($this->getType()=='file' && $this->getMultiple())
$_multiple = ' multiple';
$html = '<input id="'.$this->getHtmlId().'" name="'.$this->getName()
.'" value="'.$this->getEscapedValue().'" '.$this->serialize($this->getHtmlAttributes()).$_multiple.'/>'."\n";
$html.= $this->getAfterElementHtml();
return $html;
}
now open form.php in your module say:
app/code/community/module name/namespace/Block/Adminhtml/Libraryfile/Edit/Tab/Form.php
add field:
$fieldset->addField('file_path', 'file', array(
'label' => Mage::helper('libraryfile')->__('File'),
'name' => 'file_path[]',
'multiple' => 'multiple',
'mulitple' => true,
'note' => '(*.pdf, *.txt, *.doc, *.docx, *.xls, *.xlsx)',
));
now change in your controller :
add this into your saveAction method:
$i=0;
foreach ($_FILES['file_path']['name'] as $key => $image) {
$path = Mage::getBaseDir('media') . DS . 'libraryfile' . DS .'libraryfile'.DS;
$uploader = new Mage_Core_Model_File_Uploader(
array( 'name' => $_FILES['file_path']['name'][$i],
'type' => $_FILES['file_path']['type'][$i],
'tmp_name' => $_FILES['file_path']['tmp_name'][$i],
'error' => $_FILES['file_path']['error'][$i],
'size' => $_FILES['file_path']['size'][$i] ));
$uploader->setAllowedExtensions(array('pdf','txt','doc','docx','xlsx','xls'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path.$image;
$filename = $uploader->save($path, $image);
$uploader->save($path, $filename);
$post_data['file_path']='/media/libraryfile/libraryfile/'.$image;
//addedby Ankur Rai
$i++ }
Thats it :)
Enjoy
go to lib/Varien/Data/Form/Element/Abstract.php
look for function and replace
public function getElementHtml()
{
if($this->getType()=='file' && $this->getMultiple())
$_multiple = ' multiple';
$html = '<input id="'.$this->getHtmlId().'" name="'.$this->getName()
.'" value="'.$this->getEscapedValue().'" '.$this->serialize($this->getHtmlAttributes()).$_multiple.'/>'."\n";
$html.= $this->getAfterElementHtml();
return $html;
}
now open form.php in your module say:
app/code/community/module name/namespace/Block/Adminhtml/Libraryfile/Edit/Tab/Form.php
add field:
$fieldset->addField('file_path', 'file', array(
'label' => Mage::helper('libraryfile')->__('File'),
'name' => 'file_path[]',
'multiple' => 'multiple',
'mulitple' => true,
'note' => '(*.pdf, *.txt, *.doc, *.docx, *.xls, *.xlsx)',
));
now change in your controller :
add this into your saveAction method:
$i=0;
foreach ($_FILES['file_path']['name'] as $key => $image) {
$path = Mage::getBaseDir('media') . DS . 'libraryfile' . DS .'libraryfile'.DS;
$uploader = new Mage_Core_Model_File_Uploader(
array( 'name' => $_FILES['file_path']['name'][$i],
'type' => $_FILES['file_path']['type'][$i],
'tmp_name' => $_FILES['file_path']['tmp_name'][$i],
'error' => $_FILES['file_path']['error'][$i],
'size' => $_FILES['file_path']['size'][$i] ));
$uploader->setAllowedExtensions(array('pdf','txt','doc','docx','xlsx','xls'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path.$image;
$filename = $uploader->save($path, $image);
$uploader->save($path, $filename);
$post_data['file_path']='/media/libraryfile/libraryfile/'.$image;
//addedby Ankur Rai
$i++ }
Thats it :)
Enjoy
Comments
Post a Comment