function file_validate_is_image
7.x file.inc | file_validate_is_image(stdClass $file) |
6.x file.inc | file_validate_is_image(&$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
1 call to file_validate_is_image()
- FileValidatorTest::testFileValidateIsImage in drupal-7.x/
modules/ simpletest/ tests/ file.test - This ensures a specific file is actually an image.
3 string references to 'file_validate_is_image'
- system_theme_settings_validate in drupal-7.x/
modules/ system/ system.admin.inc - Validator for the system_theme_settings() form.
- user_validate_picture in drupal-7.x/
modules/ user/ user.module - Validates an image uploaded by a user.
- _file_test_form_submit in drupal-7.x/
modules/ simpletest/ tests/ file_test.module - Process the upload.
File
- drupal-7.x/
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;
}