You are here

function _webform_edit_file_check_directory in Webform 7.3

Same name and namespace in other branches
  1. 5.2 components/file.inc \_webform_edit_file_check_directory()
  2. 5 components/file.inc \_webform_edit_file_check_directory()
  3. 6.3 components/file.inc \_webform_edit_file_check_directory()
  4. 6.2 components/file.inc \_webform_edit_file_check_directory()
  5. 7.4 components/file.inc \_webform_edit_file_check_directory()

A Form API after build and validate function.

Ensure that the destination directory exists and is writable.

1 string reference to '_webform_edit_file_check_directory'
_webform_edit_file in components/file.inc
Implements _webform_edit_component().

File

components/file.inc, line 211
Webform module file component.

Code

function _webform_edit_file_check_directory($element) {
  $scheme = $element['extra']['scheme']['#value'];
  $directory = $element['extra']['directory']['#value'];
  $destination_dir = file_stream_wrapper_uri_normalize($scheme . '://webform/' . $directory);

  // Sanity check input to prevent use parent (../) directories.
  if (preg_match('/\\.\\.[\\/\\\\]/', $destination_dir . '/')) {
    form_error($element['extra']['directory'], t('The save directory %directory is not valid.', array(
      '%directory' => $directory,
    )));
  }
  else {
    $destination_success = file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
    if (!$destination_success) {
      form_error($element['extra']['directory'], t('The save directory %directory could not be created. Check that the webform files directory is writable.', array(
        '%directory' => $directory,
      )));
    }
  }
  return $element;
}