Magento – empty $_FILES while uploading files in adminhtml

You made a form in adminhtml with upload file but in the controller the $_FILES var is hopelessly empty ?
You probably forgot to add “‘enctype’ => ‘multipart/form-data’,” on your form declaration

example :
file : /app/code/local/Adin/Shipping/Block/Adminhtml/Delivery/Cost/Import/Edit/Form.php

protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
            'id'        => 'edit_form',
            'action'    => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
            'method'    => 'post',
            'enctype'   => 'multipart/form-data',
        ));

 $fieldset->addField('fichier', 'file', array(
            'label'     => $helper->__('Data file'),
            'value'	=> 'upload',
            'name'  => 'fichier',
            'after_element_html'     => $helper->__('<small>File from carrier</small>'),
            'required'  => true,
        ));

Leave a Reply