json([ 'status' => 'error', 'message' => 'Folder not accessible', ], 500); } $files = array_filter(scandir($path), function($file) use ($path) { return $file !== '.' && $file !== '..' && is_file($path . $file) && pathinfo($file, PATHINFO_EXTENSION) === 'txt'; }); if (empty($files)) { return response()->json([ 'status' => 'error', 'message' => 'No text files found', ], 404); } $data = []; foreach ($files as $file) { $filePath = $path . $file; // Read file content safely $content = file_get_contents($filePath); $data[] = [ 'filename' => $file, 'content' => $content, ]; } return response()->json([ 'status' => 'success', 'files' => $data, ]); } /** * Display the specified resource. */ public function show(string $id) { // } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } }