_file_generic_settings_file_directory_validate

Versions
7
_file_generic_settings_file_directory_validate($element, &$form_state)

Element validate callback for the file destination field.

Remove slashes from the beginning and end of the destination value and ensure that the file directory path is not included at the beginning of the value.

Code

modules/file/file.field.inc, line 191

<?php
function _file_generic_settings_file_directory_validate($element, &$form_state) {
  // Strip slashes from the beginning and end of $widget['file_directory'].
  $value = trim($element['#value'], '\\/');

  // Do not allow the file path to be the same as the file_directory_path().
  // This causes all sorts of problems with things like file_create_url().
  if (strpos($value, file_directory_path()) === 0) {
    form_error($element, t('The file directory (@file_directory) cannot start with the system files directory (@files_directory), as this may cause conflicts when building file URLs.', array('@file_directory' => $form_state['values']['file_directory'], '@files_directory' => file_directory_path())));
  }
  else {
    form_set_value($element, $value, $form_state);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.