You are here

function _value_is_get_file in Value is 7

Helper to get a file from $_FILES.

1 call to _value_is_get_file()
_value_is_file_element_process in ./value_is.module
Process callback for file input elements.

File

./value_is.module, line 57
All the element validators for #element_validate.

Code

function _value_is_get_file($element) {
  $input_name = trim(str_replace(array(
    '[',
    ']',
  ), ' ', str_replace('[]', '', $element['#name'])));
  $input_name_path = preg_split('/\\s+/', $input_name);

  // Traverse $_FILES recursively to find the actual file. This is not pretty, but
  // the only (?) way.
  $properties = array(
    'name',
    'type',
    'tmp_name',
    'error',
    'size',
  );
  $input_name_part = array_shift($input_name_path);
  foreach ($properties as $prop) {
    $source[$prop] = @$_FILES[$input_name_part][$prop];
    if ($source[$prop] === NULL) {
      return;
    }
  }
  while ($input_name_part = array_shift($input_name_path)) {
    foreach ($properties as $prop) {
      $source[$prop] = @$source[$prop][$input_name_part];
      if ($source[$prop] === NULL) {
        return;
      }
    }
  }

  // Flip array 2d for arrayed/multiple files.
  if ($source && is_array($source['error'])) {
    $source = _value_is_flip_array_2d($source);
  }
  return $source;
}