function file_validate_is_image

Same name in other branches
  1. 9 core/modules/file/file.module \file_validate_is_image()
  2. 8.9.x core/modules/file/file.module \file_validate_is_image()
  3. 10 core/modules/file/file.module \file_validate_is_image()

Checks 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

1 call to file_validate_is_image()
FileValidatorTest::testFileValidateIsImage in modules/simpletest/tests/file.test
This ensures a specific file is actually an image.

File

includes/file.inc, line 1860

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.