$_FILES superglobal array key is not what file.inc expects I'm trying to do some custom stuff with a file upload field via the form API. I call to file_save_upload() but it thinks that the upload is empty because it's examining $_FILES['files'] but for some reason, my file is actually in $_FILES['CSV_file'] even when the file I uploaded is not a csv.

How might files superglobal end up with a CSV_file array key?

UPDATE

So apparently the form array

$form['my_menu_csv'] = array(
  '#name' =&gt; 'CSV files',
  '#type' =&gt; 'file',
  '#title' =&gt; t('Choose a CSV file'),
  '#title_display' =&gt; 'invisible',
  '#size' =&gt; 22,
  '#theme_wrappers' =&gt; array(),
  '#weight' =&gt; -10,
);


was causing the field to have the following HTML:

&lt;input type="file" id="edit-my-menu-csv" name="CSV file" size="22" class="form-file"&gt;


and apparently the files array goes like $_FILES[$name], where $name = whatever the name attribute is in the HTML element. Makes sense! What doesn't make sense is why file_save_upload() expects to only ever encounter $_FILES['files'] but the form API uses a custom field name. Is this a bug in the form API?
I don't think it's a bug.

$_FILES['files'] is hard-coded into file_save_upload().

I believe you need to change how you construct your #name property.  The usage example in the Form API does it like this:

'#name' =&gt; 'files[' . implode('_', $element['#parents']) . ']',