Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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 Jan 16 '12 at 19:45
up vote 0 down vote accepted

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

share|improve this answer
That's only for managed files. And only in entity forms. Close enough though. And very relevant to my new project. – Rudie Jan 10 '13 at 22:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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