You are here

function image_import_validate_file in Image 6

Same name and namespace in other branches
  1. 7 contrib/image_import/image_import.pages.inc \image_import_validate_file()

Verify a candidate file for import.

Parameters

$file: A file object to check, of the format returned by file_scan_directory().

1 call to image_import_validate_file()
image_import_form in contrib/image_import/image_import.pages.inc
Form generating function for the image import page.

File

contrib/image_import/image_import.pages.inc, line 9

Code

function image_import_validate_file($file) {
  $errors = array();
  $info = image_get_info($file->filename);
  if ($info && !empty($info['extension'])) {
    $file->height = $info['height'];
    $file->width = $info['width'];
  }
  else {
    $errors[] = t('Not a JPG, GIF or PNG file.');
    $file->height = $file->width = 0;
  }

  // Check files are not too large to import.
  $file->filesize = filesize($file->filename);
  if ($file->filesize > variable_get('image_max_upload_size', 800) * 1024) {
    $errors[] = t('File too big.');
  }
  return $errors;
}