function mfw_managed_file_save_upload in Multiupload Filefield Widget 7
Given a mfw_managed_file element, save any files that have been uploaded into it.
Mostly copied from file.module.
Parameters
$element: The FAPI element whose values are being saved.
Return value
The file object representing the file that was saved, or FALSE if no file was saved.
1 call to mfw_managed_file_save_upload()
- mfw_managed_file_value in ./
multiupload_filefield_widget.module - The #value_callback for a mfw_managed_file type element.
File
- ./
multiupload_filefield_widget.module, line 137
Code
function mfw_managed_file_save_upload($element) {
$last_parent = array_pop($element['#parents']);
$upload_name = implode('_', $element['#parents']) . '_' . $element['#file_upload_delta_original'];
array_push($element['#parents'], $last_parent);
$file_number = $last_parent - $element['#file_upload_delta_original'];
if (isset($_FILES['files']['name'][$upload_name][$file_number])) {
$name = $_FILES['files']['name'][$upload_name][$file_number];
if (empty($name)) {
return FALSE;
}
$destination = isset($element['#upload_location']) ? $element['#upload_location'] : NULL;
if (isset($destination) && !file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {
watchdog('file', 'The upload directory %directory for the file field !name could not be created or is not accessible. A newly uploaded file could not be saved in this directory as a consequence, and the upload was canceled.', array(
'%directory' => $destination,
'!name' => $element['#field_name'],
));
form_set_error($upload_name, t('The file could not be uploaded.'));
return FALSE;
}
if (!($file = mfw_file_save_upload($upload_name, $file_number, $element['#upload_validators'], $destination))) {
watchdog('file', 'The file upload failed. %upload', array(
'%upload' => $upload_name,
));
form_set_error($upload_name, t('The file in the !name field was unable to be uploaded.', array(
'!name' => $element['#title'],
)));
return FALSE;
}
return $file;
}
else {
return FALSE;
}
}