On this page
function file_validate_is_image
file_validate_is_image(stdClass $file)
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
Related topics
File
- includes/file.inc, line 1774
- API for handling file uploads and server file management.
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;
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!file.inc/function/file_validate_is_image/7.x