file_validate_is_image

  1. drupal
    1. 6
    2. 8
    3. 7
Versions
6 file_validate_is_image(&$file)
7 – 8 file_validate_is_image(stdClass $file)

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

Parameters

$file A Drupal file object.

Return value

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

See also

hook_file_validate()

Related topics

Code

includes/file.inc, line 1735

<?php
function file_validate_is_image(stdClass $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;
}
?>