You are here

function _webform_submit_file in Webform 5

Same name and namespace in other branches
  1. 5.2 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 265

Code

function _webform_submit_file(&$data, $component) {

  // Hack to get the form value for this file component (not necessary in D6).
  global $form_values;
  $data = $form_values[$component['form_key']];
  $current_file = unserialize($data);
  if ($file = file_check_upload($component['form_key'])) {
    $upload_dir = variable_get('file_directory_path', 'files') . "/webform/" . $component['extra']['savelocation'];
    if (file_check_directory($upload_dir, FILE_CREATE_DIRECTORY)) {
      $file_saved = file_save_upload($component['form_key'], $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 {
        $data = serialize((array) $file_saved);
        file_delete($current_file['filepath']);
      }
    }
    else {
      drupal_set_message(t("The uploaded file was unable to be saved. The destination directory does not exist.", "error"));
    }
  }
}