You are here

function filefield_validate_is_image in FileField 6.3

An #upload_validators callback. Check that a file is an image.

This check should allow any image that PHP can identify, including png, jpg, gif, tif, bmp, psd, swc, iff, jpc, jp2, jpx, jb2, xbm, and wbmp.

This check should be combined with filefield_validate_extensions() to ensure only web-based images are allowed, however it provides a better check than extension checking alone if the mimedetect module is not available.

Parameters

$file: A Drupal file object.

Return value

An array of any errors cause by this file if it failed validation.

File

./filefield.module, line 942
FileField: Defines a CCK file field type.

Code

function filefield_validate_is_image(&$file) {
  $errors = array();
  $info = image_get_info($file->filepath);
  if (!$info || empty($info['extension'])) {
    $errors[] = t('The file is not a known image format.');
  }
  return $errors;
}