如何使用Magneto在我的自定义模块中创建多文件上传器?
这是我目前的表格代码:
$fieldset->addField('uploadpdf', 'file', array(
'label' => Mage::helper('promotionsoffers')->__('Upload PDF'),
'name' => 'uploadpdf',
));
答案 0 :(得分:1)
看看@ uploading files in magento
在/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) {
}
}