file_validate_is_image

Definition

file_validate_is_image(&$file)
drupal/includes/file.inc, line 1041

Description

Check that the file is recognized by image_get_info() as an image.

@see hook_file_validate()

Parameters

$file A Drupal file object.

Return value

An array. If the file is not an image, it will contain an error message.

Related topics

Namesort iconDescription
File interfaceCommon file handling functions.

Code

function file_validate_is_image(&$file) {
  $errors = array();

  $info = image_get_info($file->filepath);
  if (!$info || empty($info['extension'])) {
    $errors[] = t('Only JPEG, PNG and GIF images are allowed.');
  }

  return $errors;
}