You are here

function taxonomy_xml_import_form_validate in Taxonomy import/export via XML 5

Same name and namespace in other branches
  1. 5.2 taxonomy_xml.module \taxonomy_xml_import_form_validate()
  2. 7 taxonomy_xml.admin.inc \taxonomy_xml_import_form_validate()

Imports the actual XML.

File

./taxonomy_xml.module, line 191
taxonomy_xml.module This module makes it possible to import and export taxonomies as XML documents.

Code

function taxonomy_xml_import_form_validate($form_id, $form_values) {
  if ($file = file_check_upload('xml')) {
    $fd = fopen($file->filepath, "rb");
    if (!$fd) {
      form_set_error('xml', t('Vocabulary import failed: file %filename cannot be read.', array(
        '%filename' => $file->filename,
      )));
    }
    else {
      $info = fstat($fd);
      $len = $info["size"];
      $text = fread($fd, $len);
      fclose($fd);
      drupal_set_message(t('Loaded file %filename. Now processing it.', array(
        '%filename' => $file->filename,
      )));
      $form_values['file'] = $file;
      taxonomy_xml_invoke_import($text, $form_values);
    }
  }
  else {
    form_set_error('xml', t('Vocabulary import failed: file was not uploaded.'));
  }
}