You are here

function site_verify_validate_file in Site verification 6

Validation callback; save the uploaded file and check file name uniqueness.

1 string reference to 'site_verify_validate_file'
site_verify_edit_form in ./site_verify.admin.inc

File

./site_verify.admin.inc, line 160

Code

function site_verify_validate_file(&$form, &$form_state) {
  $values =& $form_state['values'];

  // Import the uploaded verification file.
  if ($file = file_save_upload('file_upload', array(), FALSE, FILE_EXISTS_REPLACE)) {
    $contents = @file_get_contents($file->filepath);
    file_delete($file->filepath);
    if ($contents === FALSE) {
      drupal_set_message(t('The verification file import failed, because the file %filename could not be read.', array(
        '%filename' => $file->filename,
      )), 'error');
    }
    else {
      $values['file'] = $file->filename;
      $values['file_contents'] = $contents;

      //drupal_set_message(t('The verification file <a href="@filename">@filename</a> was successfully imported.', array('@filename' => $file->filename)));
    }
  }
  if ($values['file']) {
    $existing_file = db_result(db_query("SELECT svid FROM {site_verify} WHERE LOWER(file) = LOWER('%s') AND svid <> %d", $values['file'], $values['svid']));
    if ($existing_file) {
      form_set_error('file', t('The file %filename is already being used in another verification.', array(
        '%filename' => $values['file'],
      )));
    }
  }
}