Thanks to some help from clive. I've cleaned up the code below. Now it appears I need to do some tweaking with my submit handler as my files are still getting mark as temporary in the file_managed
table. Also is there a way to stop drupal from adding the _
in front of the file extension on upload?
Form
$form['model_wrapper_container']['ios_file'] = array(
'#type' => 'managed_file',
'#title' => t('IOS File'),
'#size' => 22,
'#upload_location' => 'public://ios_images',
'#upload_validators' => array(
'file_validate_extensions' => array('bin aes tar'),
),
);
Submit Handler
function iosupload_submit($form, &$form_state) {
// Load the file via file.fid.
$file = file_load($form_state['values']['ios_file']);
// Change status to permanent.
$file->status = FILE_STATUS_PERMANENT;
// Save.
file_save($file);
}
'#upload_location' => 'public://path/to/folder'
on the form element, and Drupal will handle the rest :) – Clive♦ Jul 8 '12 at 0:57