I've made a form. Now I want it to upload files. I've made a form element to do that:

  $form['attachments'] = array(
    '#type' => 'file',
    '#title' => t('Attachments'),
    '#name' => 'attachments[]',
    '#attributes' => array('multiple' => ''),

I've set #name and #attributes.multiple because I want to use the HTML5 multiple files upload thingie. They invented that for a very good reason. I assume Drupal knows how to handle that.

How do I get the files in the submit handler? I don't want to save them to the file system. I want to e-mail them.

Ofcourse (?) I can just query $_FILES, but even I think that's not right in a framework like Drupal.

Is there a better way?

  • I don't think [form api file element type][1] supports that as of now, there is a html5 core initiative for D8 and hopefully we will see it change in D8. For now, you can try [plupload element type][2] (Abandoned project :( ) which uses the plupload js library by default, maybe you can take your hint from this module. [1]: api.drupal.org/api/drupal/… [2]: drupal.org/project/plupload
    – Dipen
    Commented Jan 16, 2012 at 19:45

1 Answer 1


I haven't tried HTML5 Upload yet, but it might help you out.

  • 1
    That's only for managed files. And only in entity forms. Close enough though. And very relevant to my new project.
    – Rudie
    Commented Jan 10, 2013 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.