Improve error handling in readFiles method for directory access and readability
This commit is contained in:
@@ -62,30 +62,33 @@ class SapFileController extends Controller
|
||||
|
||||
$path = "/LaserPRD/{$plantCode}";
|
||||
|
||||
$isDir = is_dir($path);
|
||||
$isReadable = is_readable($path);
|
||||
// $isDir = is_dir($path);
|
||||
// $isReadable = is_readable($path);
|
||||
|
||||
if (!$isDir || !$isReadable) {
|
||||
// Check if folder exists
|
||||
if (!is_dir($path)) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Folder not accessible',
|
||||
'debug' => [
|
||||
'path_checked' => $path,
|
||||
'is_dir' => $isDir,
|
||||
'is_readable' => $isReadable,
|
||||
]
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Folder for plant-code {$plantCode} not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
if (!is_readable($path)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Folder for plant-code {$plantCode} exists but is not readable!"
|
||||
], 500);
|
||||
}
|
||||
|
||||
// Scan folder
|
||||
$allFiles = scandir($path);
|
||||
if ($allFiles === false) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to scan directory',
|
||||
'debug' => ['path_checked' => $path]
|
||||
], 500);
|
||||
}
|
||||
// Scan folder
|
||||
$allFiles = scandir($path);
|
||||
if ($allFiles === false) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to scan directory',
|
||||
'debug' => ['path_checked' => $path]
|
||||
], 500);
|
||||
}
|
||||
|
||||
$files = array_filter($allFiles, function($item) use ($path) {
|
||||
$fullPath = $path . '/' . $item;
|
||||
|
||||
Reference in New Issue
Block a user