$file, 'size' => filesize($path), 'date' => date('Y-m-d', filemtime($path)), 'path' => rawurlencode($file) ]; } } return $files; } try { $files = scanDirectory('.'); echo json_encode($files); } catch (Exception $e) { http_response_code(500); echo json_encode(['error' => $e->getMessage()]); } ?>