0

How can I create a multiple file uploader in my custom module using Magneto?

This is my current form code:

$fieldset->addField('uploadpdf', 'file', array(
    'label' => Mage::helper('promotionsoffers')->__('Upload PDF'),
    'name'  => 'uploadpdf', 
));
johnkavanagh
  • 4,614
  • 2
  • 25
  • 37
Vinoth
  • 77
  • 1
  • 1
  • 5
  • you have asked same question with different title twice. I have answered your another question http://stackoverflow.com/questions/20391720/how-to-create-more-than-one-single-file-upload-click-the-add-field-button-for – Deependra Singh Dec 07 '13 at 13:59

1 Answers1

1

Take a look @ uploading files in magento

In /app/code/local/Company/ModName/controllers/Adminhtml/ModuleNameController.php

if(isset($_FILES['uploadpdf']['name']) and (file_exists($_FILES['uploadpdf']['tmp_name']))) {
  try {
    $uploader = new Varien_File_Uploader('uploadpdf');
    $uploader->setAllowedExtensions(array('pdf')); // or pdf or anything


    $uploader->setAllowRenameFiles(false);

    // setAllowRenameFiles(true) -> move your file in a folder the magento way
    // setAllowRenameFiles(true) -> move your file directly in the $path folder
    $uploader->setFilesDispersion(false);

    $path = Mage::getBaseDir('media') . DS ;

    $uploader->save($path, $_FILES['uploadpdf']['name']);

    $data['uploadpdf'] = $_FILES['uploadpdf']['name'];
  }catch(Exception $e) {

  }
}
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62