function _webform_submit_file in Webform 6.2
Same name and namespace in other branches
- 5.2 components/file.inc \_webform_submit_file()
- 5 components/file.inc \_webform_submit_file()
- 6.3 components/file.inc \_webform_submit_file()
- 7.4 components/file.inc \_webform_submit_file()
- 7.3 components/file.inc \_webform_submit_file()
Perform additional server-side processing on the submitted data, such as managing an uploaded file.
Parameters
$data: The POST data associated with the component.
$component: An array of information describing the component, directly correlating to the webform_component database schema.
Return value
Nothing.
File
- components/
file.inc, line 359 - Webform module file component.
Code
function _webform_submit_file(&$data, $component) {
$upload_dir = file_directory_path() . '/webform/' . $component['extra']['savelocation'];
if (!empty($_FILES['files']['name'][$data['new']])) {
if (file_check_directory($upload_dir, FILE_CREATE_DIRECTORY)) {
$file_saved = file_save_upload($data['new'], array(), $upload_dir);
if (!$file_saved) {
drupal_set_message(t('The uploaded file %filename was unable to be saved. The destination directory may not be writable.', array(
'%filename' => $file_saved['filename'],
)), 'error');
}
else {
@chmod($file_saved->filepath, 0664);
file_set_status($file_saved, FILE_STATUS_PERMANENT);
if (isset($data['existing']['filepath'])) {
file_delete($data['existing']['filepath']);
}
$data = serialize((array) $file_saved);
}
}
else {
drupal_set_message(t('The uploaded file was unable to be saved. The destination directory does not exist.'), 'error');
}
}
else {
$data = serialize(array());
}
}