I'm trying to build a theme that will require unmanaged files, ie images, and handle the choosing of those in the theme settings.
I am therefore doing this in the theme settings file:
$form['images']['common']['header'] = array(
'#name' => 'header_image',
'#type' => 'file',
'#title' => t('Header image'),
'#title_display' => 'invisible',
'#size' => 22,
'#prefix' => '<h4 class="settings-header">Header Image:</h4>',
'#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif. Choose the highest resolution Landscape image.'),
'#weight' => -9,
);
But when I submit the image, the form_state value for the image field is empty. I've checked the temp storage, and the file is not being uploaded there. Other images uploaded, eg in creation of nodes, work fine.
Hi onyx. The
file
FAPI type is a "primitive" type that doesn't get processed and therefore is not included in$form_state['values']
. It's used by other types to move the file to the correct location, etc, etc (all the processing).You CAN actually get the file in your submit handlers. For example, these are the form builder and submit handler:
The superglobal variable
$_FILES
is an array that contains the following:The most important bit here is:
/Applications/MAMP/tmp/php/phpZq4TsJ
THAT is a temporary file that is stored in the tmp folder of your site. Within the submit handler, you can do whatever you want with it, such as copy it to a different location and rename it.Be aware that the temporary file gets deleted as soon as the page request is completed!