Enhance readFiles method in SapFileController with improved error handling and debugging information
This commit is contained in:
@@ -32,15 +32,34 @@ class SapFileController extends Controller
|
|||||||
|
|
||||||
$path = "/srv/pds.iotsignin.com/sapftp/In/";
|
$path = "/srv/pds.iotsignin.com/sapftp/In/";
|
||||||
|
|
||||||
// $files = scandir($path);
|
$isDir = is_dir($path);
|
||||||
if (!is_dir($path) || !is_readable($path)) {
|
$isReadable = is_readable($path);
|
||||||
|
|
||||||
|
if (!$isDir || !$isReadable) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'message' => 'Folder not accessible',
|
'message' => 'Folder not accessible',
|
||||||
|
'debug' => [
|
||||||
|
'path_checked' => $path,
|
||||||
|
'is_dir' => $isDir,
|
||||||
|
'is_readable' => $isReadable,
|
||||||
|
'php_user' => get_current_user(),
|
||||||
|
]
|
||||||
], 500);
|
], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
$files = array_filter(scandir($path), function($file) use ($path) {
|
// 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)
|
return $file !== '.' && $file !== '..' && is_file($path . $file)
|
||||||
&& pathinfo($file, PATHINFO_EXTENSION) === 'txt';
|
&& pathinfo($file, PATHINFO_EXTENSION) === 'txt';
|
||||||
});
|
});
|
||||||
@@ -49,6 +68,9 @@ class SapFileController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'message' => 'No text files found',
|
'message' => 'No text files found',
|
||||||
|
'debug' => [
|
||||||
|
'scanned_files' => $allFiles
|
||||||
|
]
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user