function _webform_edit_file_check_directory in Webform 7.4
Same name and namespace in other branches
- 5.2 components/file.inc \_webform_edit_file_check_directory()
- 5 components/file.inc \_webform_edit_file_check_directory()
- 6.3 components/file.inc \_webform_edit_file_check_directory()
- 6.2 components/file.inc \_webform_edit_file_check_directory()
- 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 234 - 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);
$tokenized_dir = drupal_strtolower(webform_replace_tokens($destination_dir, $element['#node']));
// Sanity check input to prevent use parent (../) directories.
if (preg_match('/\\.\\.[\\/\\\\]/', $tokenized_dir . '/')) {
form_error($element['extra']['directory'], t('The save directory %directory is not valid.', array(
'%directory' => $tokenized_dir,
)));
}
else {
if (!file_prepare_directory($tokenized_dir, FILE_CREATE_DIRECTORY)) {
form_error($element['extra']['directory'], t('The save directory %directory could not be created. Check that the webform files directory is writable.', array(
'%directory' => $tokenized_dir,
)));
}
}
return $element;
}