I have this in my form function:

$form['#attributes'] = array('enctype' => 'multipart/form-data');
... other form fields
$form['form']['form_file'] =  array (
    '#type' => 'file',
    '#name' => 'form_file',
    '#attributes' => array ('class' => 'textarea_crmform'),

and when I call file_save_upload in my submit function, I am doing this:

if ($file = file_save_upload('form_file'))

But it never gets into the above if statement.


My guess is that there's an error. Have you looked at your watchdog log? Is the temporary directory setup and writable by the web server?

| improve this answer | |
  • The temporary directory is set up to be writeable. Also, I made a small form on the side as shown here: computerminds.co.uk/file-uploads-drupal-6-part-1 and it worked fine. I don't have any errors listed from the module I am making. The difference between my form and the example is that I have a 2D array and the example as a 1D array. I am wondering if this is the issue and how I would deal with using a 2D array. – Will Jun 4 '15 at 20:56
  • What about checking the watchdog log ... anything there? Also, try naming the first dimension something else than form and remove the #name parameter. – Purdy Jun 4 '15 at 21:13
  • Thank you. I changed the name from form, but this didn't seem to fix it. However, Removing the #name parameter did it. Any idea as to why that is? – Will Jun 4 '15 at 21:15
  • Not sure - the input name usually comes from the array key, so maybe since they were the same value, something kooky happened. Glad it works now! Back away slowly... ;) – Purdy Jun 4 '15 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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