diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index a6f1589..52abff0 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -103,8 +103,26 @@ private function uploadTableCsv($doUnicode) ], 423); } + if (empty($reader)) { + return $this->sendError([ + 'data' => [ + 'errors' => array(), + 'message' => __('The imported CSV file is empty.', 'ninja-tables') + ] + ], 423); + } + $header = array_shift($reader); + if (empty($header) || !is_array($header)) { + return $this->sendError([ + 'data' => [ + 'errors' => array(), + 'message' => __('The imported CSV file is missing a header row.', 'ninja-tables') + ] + ], 423); + } + $tableId = $this->createTable(array( 'post_title' => $fileName, 'post_content' => '', @@ -426,6 +444,13 @@ public function extracted($data) $data = ninja_tables_sanitize_array($data); + if (empty($data)) { + return $this->sendError([ + 'errors' => array(), + 'message' => __('The imported file does not contain any rows.', 'ninja-tables') + ], 423); + } + $tableId = $this->savedDragAndDropTable($data, $fileName); return $this->sendSuccess([