You are here

function file_validate in Image FUpload 6.3

This function allows to validate a file on given $validator functions. This code is taken from file_save_upload (D 6.4) (22.09.2008)

Parameters

object $file:

array $validators:

Return value

Boolean returns TRUE, if validation was successful, otherwise FALSE

1 call to file_validate()
image_fupload_image_node_create in image_fupload_image/image_fupload_image.module

File

./image_fupload.module, line 261

Code

function file_validate($file, $validators = array()) {

  // Call the validation functions.
  $errors = array();
  foreach ($validators as $function => $args) {
    array_unshift($args, $file);
    $errors = array_merge($errors, call_user_func_array($function, $args));
  }

  // Check for validation errors.
  if (!empty($errors)) {
    $message = t('The selected file %name could not be uploaded.', array(
      '%name' => $file->filename,
    ));
    if (count($errors) > 1) {
      $message .= '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>';
    }
    else {
      $message .= ' ' . array_pop($errors);
    }
    form_set_error($source, $message);
    return FALSE;
  }
  else {

    // Validation successful =)
    return TRUE;
  }
}