atr_file_validate

Versions
6.1
atr_file_validate($element, &$form_state)

Form validate handler for 'atr_file'.

Code

atr/atr.module, line 566

<?php
function atr_file_validate($element, &$form_state) {
  $paths = array();
  $parents = array_reverse($element['#array_parents']);
  $parent = $parents[1];
  // Process the online file.
  // TODO: Throw an error if the path cannot be read.
  if ($element['#value']) {
    // Make sure the path doesn't start with a slash, but only ends with one.
    $paths['online'] = trim($element['#value'], ' /');
    // Check if the source is a directory.
    if (strpos($paths['online'], '.', strrpos($paths['online'], '/')) === FALSE) {
      $paths['online'] .= '/';
    }
    else {
      module_load_include('inc', 'atr', 'includes/atr.extract');
      atr_file_get($paths['online'], basename($paths['online']));
    }
  }
  // Process the uploaded file.
  if ($path_upload = $_FILES['files']['tmp_name'][$parent . '_upload']) {
    $paths['upload'] = $path_upload;
    module_load_include('inc', 'atr', 'includes/atr.extract');
    atr_file_get($paths['upload'], $_FILES['files']['name'][$parent . '_upload']);
  }

  // Save the paths as the 'atr_file' element's value.
  $atr_file_element = array(
    '#parents' => array($parent),
  );
  form_set_value($atr_file_element, $paths, $form_state);
}
?>