You are here

function clamav_elements_filefield_validate in ClamAV 6

Validator for filefield widget and imagefield widget. This is an implementation of a file upload_validator.

File

./clamav.module, line 159
Integrate ClamAV to allow uploaded files to be scanned for viruses.

Code

function clamav_elements_filefield_validate($file) {
  $filepath = $file->filepath;
  $form_error_key = $file->source;
  require_once dirname(__FILE__) . '/clamav.inc';
  $result = clamav_scan_file($filepath);
  $errors = array();
  if ($result == CLAMAV_SCANRESULT_INFECTED) {
    $errors[] = t('A virus has been detected in the file.  The file will not be accepted.');
  }
  elseif ($result == CLAMAV_SCANRESULT_UNCHECKED && variable_get('clamav_unchecked_files', CLAMAV_DEFAULT_UNCHECKED) == CLAMAV_BLOCK_UNCHECKED) {
    $errors[] = t('The anti-virus scanner was not able to check the file.  The file cannot be uploaded.');
  }
  return $errors;
}