You are here

function _filefield_source_attach_file_path_validate in FileField Sources 6

Same name and namespace in other branches
  1. 7 sources/attach.inc \_filefield_source_attach_file_path_validate()
1 string reference to '_filefield_source_attach_file_path_validate'
filefield_source_attach_settings in sources/attach.inc
Implements hook_filefield_source_settings().

File

sources/attach.inc, line 97
A FileField extension to allow use of files within a server directory.

Code

function _filefield_source_attach_file_path_validate($element, &$form_state) {

  // Only validate if this source is enabled.
  if (!$form_state['values']['filefield_sources']['attach']) {
    return;
  }

  // Strip slashes from the end of the file path.
  $filepath = rtrim($element['filefield_source_attach_path']['#value'], '\\/');
  form_set_value($element['filefield_source_attach_path'], $filepath, $form_state);
  $filepath = _filefield_source_attach_directory($form_state['values']);

  // Check that the directory exists and is writable.
  if (!field_file_check_directory($filepath, FILE_CREATE_DIRECTORY)) {
    form_error($element['filefield_source_attach_path'], t('Specified file attach path must exist or be writable.'));
  }
}