Uploading from within fieldset using drupal 6 forms API not working I've got a drupal form with a fieldset (actually, two). Inside the fieldset, there are a number of dynamically generated file fields. Unfortunately, I can't seem to access these fields' contents from file_save_upload. Currently, I'm attempting to use the approach described here to set the #name property of my file fields so that the files array gets built correctly. However, file_save_upload always returns 0. What am I doing wrong?

Form (this is an example, since the actual form is dynamically generated by a bunch of code that isn't relevant here):

$form['release_data_graphics'] = array(              //This has a few other random things in it
    '#type' =&gt; 'fieldset',
    '#title' =&gt; 'Brand Release Graphics',
    '#collapsed' =&gt; FALSE,
    '#collapsible' =&gt; TRUE,
    '#weight' =&gt; 11,
);
$form['release_data_graphics']['graphics'] = array(  //This has a few other random things in it
    'folders' =&gt; array(                              //This is here because I iterate through it
        'folder1' =&gt; array(
            '#type' =&gt; 'fieldset',
            '#name' =&gt; 'Folder 1',
            '#description' =&gt; 'some description',
            'graphics' =&gt; array(                     //This is here because I iterate through it
                'graphic1' =&gt; array(
                    '#type' =&gt; 'file',
                    '#title' =&gt; 'Upload graphic 1',
                    '#name' =&gt; 'files[1]',
                ),
                'graphic2' =&gt; array(
                    '#type' =&gt; 'file',
                    '#title' =&gt; 'Upload graphic 2',
                    '#name' =&gt; 'files[2]',
                ),
            ),
        ),
    ),
);


Then, in my submit handler, I iterate through the folders and child graphics arrays (which I won't show here) with file_save_upload. My code ends up running file_save_upload like this:

graphic1 = file_save_upload('1', file_directory_path(), FILE_EXISTS_REPLACE);
graphic2 = file_save_upload('2', file_directory_path(), FILE_EXISTS_REPLACE);


When I select a few items for upload and then print the files table in the submit callback, the files table looks good:

[files] =&gt; Array(
    [1] =&gt; test1.png
    [2] =&gt; test2.png
);


So I'm really having trouble figuring out what's going on...
Add this to beginning of your form 

You need this:

$form['#attributes'] = array('enctype' =&gt; 'multipart/form-data');


Also:  

file_save_upload($source, $validators = array(), $dest = FALSE, $replace = FILE_EXISTS_RENAME)


you have

graphic1 = file_save_upload('graphic1', file_directory_path(), FILE_EXISTS_REPLACE);


you should have

$graphic1 = file_save_upload('graphic1',,file_directory_path(), FILE_EXISTS_REPLACE);


One thing I've noticed in D6 with file uploads is that using only file_save_upload() will result in your file being purged on a subsequent drupal cron run. This happens because all files are uploaded in Drupal with a status of 0.

Therefore, you should be calling your hook_submit more like this...

// Save new file uploads.
if ($file = file_save_upload('file_upload', $validators, file_directory_path())) {

// Do something with $file here.

//Make file permanent
file_set_status($file, FILE_STATUS_PERMANENT);
}