You are here

function media_internet_add_submit in D7 Media 7

Same name and namespace in other branches
  1. 7.4 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()

File

modules/media_internet/media_internet.module, line 159

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;
  }
  $form_state['redirect'] = array(
    'media/browser',
    array(
      'query' => array(
        'render' => 'media-popup',
        'fid' => $file->fid,
      ),
    ),
  );
}