function media_add_upload_multiple_submit in D7 Media 7
File
- includes/
media.pages.inc, line 279 - Common pages for the Media module.
Code
function media_add_upload_multiple_submit($form, &$form_state) {
$scheme = variable_get('file_default_scheme', 'public') . '://';
$saved_files = array();
// We can't use file_save_upload() because of http://www.jacobsingh.name/content/tight-coupling-no-not
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_save($file);
_media_save_file_permanently($file);
$saved_files[] = $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'],
)));
}
}
// Get a list of fids to pass back.
$fids = array();
foreach ($saved_files as $file) {
$fids[] = $file->fid;
}
$form_state['redirect'] = array(
'media/browser',
array(
'query' => array(
'render' => 'media-popup',
'fid' => $fids,
),
),
);
}