From 956c2820050c8d70599c33575d3330a57a649fb4 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 26 Sep 2025 11:22:52 +0530 Subject: [PATCH] Add debug response for file reading in readFiles method and improve error handling for file accessibility --- app/Http/Controllers/SapFileController.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/SapFileController.php b/app/Http/Controllers/SapFileController.php index c23a7f1b2..8da15ea97 100644 --- a/app/Http/Controllers/SapFileController.php +++ b/app/Http/Controllers/SapFileController.php @@ -124,12 +124,26 @@ class SapFileController extends Controller $fileName = array_values($files)[0]; $filePath = $path . '/' . $fileName; - $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!$lines) { return response()->json(['status' => 'ERROR', 'message' => 'File is empty'], 400); } - $table = 'class_characteristics'; + // Debug: return first 5 lines to check reading + return response()->json([ + 'status' => 'DEBUG_LINES', + 'file' => $fileName, + 'lines_sample' => array_slice($lines, 0, 5) // first 5 lines + ]); + + if (!file_exists($filePath) || !is_readable($filePath)) { + return response()->json([ + 'status' => 'ERROR', + 'message' => "File {$fileName} not found or not readable" + ], 500); + } + + $table = 'class_characteristics'; $columns = Schema::getColumnListing($table); // returns lowercase column names $rows = [];