123 lines
2.5 KiB
PHP
123 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
class SapFileController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
// public function store(Request $request)
|
|
// {
|
|
// //
|
|
// }
|
|
|
|
public function getSapData(Request $request)
|
|
{
|
|
|
|
}
|
|
|
|
public function readFiles()
|
|
{
|
|
|
|
$path = "/srv/pds.iotsignin.com/sapftp/In/";
|
|
|
|
$isDir = is_dir($path);
|
|
$isReadable = is_readable($path);
|
|
|
|
if (!$isDir || !$isReadable) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => 'Folder not accessible',
|
|
'debug' => [
|
|
'path_checked' => $path,
|
|
'is_dir' => $isDir,
|
|
'is_readable' => $isReadable,
|
|
'php_user' => get_current_user(),
|
|
]
|
|
], 500);
|
|
}
|
|
|
|
// Scan folder
|
|
$allFiles = scandir($path);
|
|
if ($allFiles === false) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => 'Failed to scan directory',
|
|
'debug' => ['path_checked' => $path]
|
|
], 500);
|
|
}
|
|
|
|
// Filter only .txt files
|
|
$files = array_filter($allFiles, 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',
|
|
'debug' => [
|
|
'scanned_files' => $allFiles
|
|
]
|
|
], 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)
|
|
{
|
|
//
|
|
}
|
|
}
|