You are here

function tft_multiple_upload_files_submit in Taxonomy File Tree 7.2

1 string reference to 'tft_multiple_upload_files_submit'
tft_multiple_upload_tft_form in modules/tft_multiple_upload/tft_multiple_upload.module

File

modules/tft_multiple_upload/tft_multiple_upload.module, line 83
Hook implementations for TFT Opigno.

Code

function tft_multiple_upload_files_submit($form, &$form_state) {
  $file_field_instance = field_info_instance('node', 'tft_file', 'tft_file');
  $file_field = field_info_field('tft_file');
  $path = file_field_widget_uri($file_field, $file_field_instance, $data = array());
  $saved_files = array();

  //Array to capture file objects
  foreach ($form_state['values']['multiple_upload'] as $uploaded_file) {
    if ($uploaded_file['status'] == 'done') {
      $source = $uploaded_file['tmppath'];
      $destination = file_stream_wrapper_uri_normalize($path . $uploaded_file['name']);
      $destination = file_unmanaged_move($source, $destination, FILE_EXISTS_RENAME);
      $file = plupload_file_uri_to_object($destination);
      file_save($file);
      $saved_files[] = $file;
    }
    else {
      form_set_error('uploadfiles', "Upload of {$uploaded_file['name']} failed");
    }
  }
  $destination = drupal_get_query_parameters();
  $destination = $destination['destination'];
  $parts = explode("/", $destination);
  $termid = $parts[count($parts) - 1];
  foreach ($saved_files as $index => $saved_file) {
    tft_multiple_upload_create_node($saved_file, $termid);
  }
}