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 1885
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'])) {
    $supported_extensions = image_get_supported_extensions();
    $errors[] = t('Only images with the following extensions are allowed: @formats.', array('@formats' => implode(', ', $supported_extensions)));
  }

  return $errors;
}