1 file.inc file_validate_is_image(File $file)

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

Parameters

File $file: A file entity.

Return value

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

See also

hook_file_validate()

Related topics

File

core/includes/file.inc, line 1848
API for handling file uploads and server file management.

Code

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

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

  return $errors;
}