You are here

function clamav_elements_file_validate in ClamAV 6

Form element validator for the file FAPI type.

Parameters

Array $element:

1 string reference to 'clamav_elements_file_validate'
clamav_elements in ./clamav.module
Implementation of hook_elements().

File

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

Code

function clamav_elements_file_validate($element) {
  $key = $element['#parents'][0];
  if (is_array($_FILES['files']['tmp_name']) && array_key_exists($key, $_FILES['files']['tmp_name']) && !empty($_FILES['files']['tmp_name'][$key])) {
    $filepath = $_FILES['files']['tmp_name'][$key];

    // filepath to the uploaded file
    $form_error_key = implode('][', $element['#parents']);

    // form-element to use with form_set_error
    require_once dirname(__FILE__) . '/clamav.inc';
    clamav_scan($filepath, $form_error_key);
  }
}