Magento: Add Encryption Type When Uploading Files in Admin

I am in the process of building a module with a custom interface for some custom data. One thing that it has to do is have the ability to upload an image for each record, very similar to uploading an image for a category. I got all the code setup, tested it out and nothing was happening with the image. Here is how my form element setup looked in the _prepareForm() method:

$form = new Varien_Data_Form(array(
    'id'        => 'edit_form',
    'action'    => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
    'method'    => 'post',
));

After looking at it with co-worker of mine, the answer to the problem was quite easy. Form encryption type. In order to upload files, you need to have ‘multipart/form-data’, so adding one extra line to the form parameters did the trick:

$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',
));

So, if you have any modules that deal with uploading files, be sure to add the encryption type to your form.

This entry was posted in Magento. Bookmark the permalink.

One Response to Magento: Add Encryption Type When Uploading Files in Admin

  1. Jim says:

    enctype is form encoding type not the encryption type.