1
0
forked from poc/pds

Refactor readFiles method to dynamically set file path and improve file handling

This commit is contained in:
dhanabalan
2025-09-26 11:16:06 +05:30
parent 086910122e
commit c9b5a59bf2

View File

@@ -120,9 +120,11 @@ class SapFileController extends Controller
// 'files' => $data,
// ]);
$fileName = 'RMGLAS02-1725800-1.txt';
//$fileName = 'RMGLAS02-1725800-1.txt';
$fileName = array_values($files)[0];
$filePath = $path . '/' . $fileName;
$lines = file($fileName, 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);
}
@@ -145,14 +147,14 @@ class SapFileController extends Controller
}
// Insert into database
foreach ($rows as $row) {
\App\Models\ClassCharacteristic::create($row);
}
foreach ($rows as $row) {
\App\Models\ClassCharacteristic::create($row);
}
return response()->json([
'status' => 'SUCCESS',
'rows_imported' => count($rows),
]);
return response()->json([
'status' => 'SUCCESS',
'rows_imported' => count($rows),
]);
}