Add debug response for file reading in readFiles method and improve error handling for file accessibility

This commit is contained in:
dhanabalan
2025-09-26 11:22:52 +05:30
parent c9b5a59bf2
commit 956c282005

View File

@@ -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 = [];