Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
1  
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

 
discard

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.