You are here

function media_internet_add_submit in D7 Media 7.4

Same name and namespace in other branches
  1. 7 modules/media_internet/media_internet.module \media_internet_add_submit()
  2. 7.2 modules/media_internet/media_internet.module \media_internet_add_submit()
  3. 7.3 modules/media_internet/media_internet.module \media_internet_add_submit()

Upload a file from a URL.

This will copy a file from a remote location and store it locally.

See also

media_parse_to_uri()

media_parse_to_file()

1 string reference to 'media_internet_add_submit'
media_internet_form_file_entity_add_upload_alter in modules/media_internet/media_internet.module
Implements hook_form_FORM_ID_alter().

File

modules/media_internet/media_internet.module, line 301

Code

function media_internet_add_submit($form, &$form_state) {
  $embed_code = $form_state['values']['embed_code'];
  try {

    // Save the remote file
    $provider = media_internet_get_provider($embed_code);

    // Providers decide if they need to save locally or somewhere else.
    // This method returns a file object
    $file = $provider
      ->save();
  } catch (Exception $e) {
    form_set_error('embed_code', $e
      ->getMessage());
    return;
  }
  if (!$file->fid) {
    form_set_error('embed_code', t('The file %file could not be saved. An unknown error has occurred.', array(
      '%file' => $embed_code,
    )));
    return;
  }
  else {
    $form_state['storage']['upload'] = $file->fid;
  }
}