You are here

function _webform_submit_file in Webform 5.2

Same name and namespace in other branches
  1. 5 components/file.inc \_webform_submit_file()
  2. 6.3 components/file.inc \_webform_submit_file()
  3. 6.2 components/file.inc \_webform_submit_file()
  4. 7.4 components/file.inc \_webform_submit_file()
  5. 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 352
Webform module file component.

Code

function _webform_submit_file(&$data, $component) {
  if ($file = file_check_upload($data['new'])) {
    $upload_dir = file_directory_path() . '/webform/' . $component['extra']['savelocation'];
    if (file_check_directory($upload_dir, FILE_CREATE_DIRECTORY)) {
      $file_saved = file_save_upload($data['new'], $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 {
        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 {
    return serialize(array());
  }
}