function media_internet_add_submit in D7 Media 7.3
Same name and namespace in other branches
- 7.4 modules/media_internet/media_internet.module \media_internet_add_submit()
- 7 modules/media_internet/media_internet.module \media_internet_add_submit()
- 7.2 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
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;
}
}