1.20.x 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
Related topics
File
- includes/
file.inc, line 1877 - 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;
}