You are here

function media_watermark_add_upload_multiple_submit in Media watermark 7

Function which make same things as file_entity__add_upload_multiple_submit().

1 call to media_watermark_add_upload_multiple_submit()
media_watermark_add_watermark in ./media_watermark.module
Callback to add watermark.

File

./media_watermark.module, line 376
Watermark media module.

Code

function media_watermark_add_upload_multiple_submit($form, &$form_state) {
  $scheme = variable_get('file_default_scheme', 'public') . '://';
  foreach ($form_state['values']['upload'] as $uploaded_file) {
    if ($uploaded_file['status'] == 'done') {
      $source = $uploaded_file['tmppath'];
      $destination = file_stream_wrapper_uri_normalize($scheme . $uploaded_file['name']);

      // Rename it to its original name, and put it in its final home.
      // Note - not using file_move here because if we call file_get_mime
      // (in file_uri_to_object) while it has a .tmp extension, it horks.
      $destination = file_unmanaged_move($source, $destination, FILE_EXISTS_RENAME);
      $file = file_uri_to_object($destination);
      $file->status = FILE_STATUS_PERMANENT;
      file_save($file);
      $form_state['files'][$file->fid] = $file;
    }
    else {

      // @todo: move this to element validate or something.
      form_set_error('pud', t('The specified file %name could not be uploaded.', array(
        '%name' => $uploaded_file['name'],
      )));
    }
  }
  $batch = media_watermark_prepare_batch($form_state);
  batch_set($batch);

  // Redirect to the file edit page.
  if (file_entity_access('edit') && module_exists('multiform')) {
    $destination = array(
      'destination' => 'admin/content/file',
    );
    if (isset($_GET['destination'])) {
      $destination = drupal_get_destination();
      unset($_GET['destination']);
    }
    $form_state['redirect'] = array(
      'admin/content/file/edit-multiple/' . implode(' ', array_keys($form_state['files'])),
      array(
        'query' => $destination,
      ),
    );
  }
  else {
    $form_state['redirect'] = 'admin/content/file';
  }
}