You are here

function _webform_edit_file_check_directory in Webform 6.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.2 components/file.inc \_webform_edit_file_check_directory()
  4. 7.4 components/file.inc \_webform_edit_file_check_directory()
  5. 7.3 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 171
Webform module file component.

Code

function _webform_edit_file_check_directory($element) {
  $base_dir = file_directory_path() . '/webform';
  $base_success = file_check_directory($base_dir, FILE_CREATE_DIRECTORY);
  $destination_dir = $base_dir . '/' . $element['#value'];

  // Sanity check input to prevent use parent (../) directories.
  if (preg_match('/\\.\\.[\\/\\\\]/', $destination_dir . '/')) {
    form_error($element, t('The save directory %directory is not valid.', array(
      '%directory' => $destination_dir,
    )));
  }
  else {

    // Try to make the directory recursively before calling file_check_directory().
    // This may be removed in D7, as recusive is the default there.
    @mkdir($destination_dir, 0775, TRUE);
    $destination_success = file_check_directory($destination_dir, FILE_CREATE_DIRECTORY);
    if (!$base_success || !$destination_success) {
      form_error($element, t('The save directory %directory could not be created. Check that the webform files directory is writtable.', array(
        '%directory' => $destination_dir,
      )));
    }
  }
  return $element;
}