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['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.
  • To offer another approach...you could use the managed_file type (which will save having to do the file upload yourself) along with a bit of javascript to auto-press the upload button. It should achieve the same effect. There's an example at drupal.stackexchange.com/questions/31121/… if you're interested – Clive Jul 8 '12 at 0:39
  • @Clive I like the sandbox module that works pretty slick! Next issue is how do I get around the allowed file types, and tell it where it should be uploaded in the public file system? Thanks – rsaturns Jul 8 '12 at 0:52
  • If you're using a managed_file you can put something like '#upload_location' => 'public://path/to/folder' on the form element, and Drupal will handle the rest :) – Clive Jul 8 '12 at 0:57
  • @Clive Duh yeah I had that in my submit handler above... I'm going to post refreshed code and reword my question current questions. Thanks – rsaturns Jul 8 '12 at 1:07

Your Answer

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

Browse other questions tagged or ask your own question.