diff --git a/app/Http/Controllers/SapFileController.php b/app/Http/Controllers/SapFileController.php index 05fc072..aeb103f 100644 --- a/app/Http/Controllers/SapFileController.php +++ b/app/Http/Controllers/SapFileController.php @@ -32,26 +32,24 @@ class SapFileController extends Controller $path = "/srv/pds.iotsignin.com/sapftp/In/"; - $files = scandir($path); + // $files = scandir($path); - $data = []; + $path = '/srv/pds.iotsignin.com/sapftp/In/'; + + $files = array_filter(scandir($path), fn($file) => + $file !== '.' && $file !== '..' && is_file($path . $file) && pathinfo($file, PATHINFO_EXTENSION) === 'txt' + ); + + $data = []; foreach ($files as $file) { - if ($file == '.' || $file == '..') continue; // skip system entries + $data[] = [ + 'filename' => $file, + 'content' => file_get_contents($path . $file), // plain text content + ]; - if (is_file($path . $file) && pathinfo($file, PATHINFO_EXTENSION) == 'txt') { - $data[] = [ - 'filename' => $file, - 'content' => file_get_contents($path . $file), - ]; - } - } - - if (empty($data)) { - return response()->json([ - 'status' => 'error', - 'message' => 'No text files found', - ], 404); + // Optional: move processed file to Out + rename($path . $file, '/srv/pds.iotsignin.com/sapftp/Out/' . $file); } return response()->json([