You are here

function _filefield_source_attach_file_path_validate in FileField Sources 7

Same name and namespace in other branches
  1. 6 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 102
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']['instance']['widget']['settings']['filefield_sources']['filefield_sources']['attach']) {
    return;
  }

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

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