diff --git a/grade/import/csv/classes/load_data.php b/grade/import/csv/classes/load_data.php index 3cbb069ae64..21477b9f582 100644 --- a/grade/import/csv/classes/load_data.php +++ b/grade/import/csv/classes/load_data.php @@ -77,17 +77,21 @@ class gradeimport_csv_load_data { $csvimport->load_csv_content($text, $encoding, $separator); $this->error = $csvimport->get_error(); - // Get header (field names). - $this->headers = $csvimport->get_columns(); - $this->trim_headers(); + // If there are no import errors then proceed. + if (empty($this->error)) { - $csvimport->init(); - $this->previewdata = array(); + // Get header (field names). + $this->headers = $csvimport->get_columns(); + $this->trim_headers(); - for ($numlines = 0; $numlines <= $previewrows; $numlines++) { - $lines = $csvimport->next(); - if ($lines) { - $this->previewdata[] = $lines; + $csvimport->init(); + $this->previewdata = array(); + + for ($numlines = 0; $numlines <= $previewrows; $numlines++) { + $lines = $csvimport->next(); + if ($lines) { + $this->previewdata[] = $lines; + } } } } diff --git a/grade/import/direct/index.php b/grade/import/direct/index.php index 1a9fc67c142..d1b6a4b730b 100644 --- a/grade/import/direct/index.php +++ b/grade/import/direct/index.php @@ -69,7 +69,7 @@ if (!$iid) { $csvimport->load_csv_content($text, $formdata->encoding, 'tab', $formdata->previewrows); $csvimporterror = $csvimport->get_error(); if (!empty($csvimporterror)) { - echo $renderer->errors($csvimport->get_error()); + echo $renderer->errors(array($csvimport->get_error())); echo $OUTPUT->footer(); die(); }