> /path/to/cleanup.log 2>&1 */ require_once 'session_manager.php'; // Check if running from command line or web $isCLI = php_sapi_name() === 'cli'; if (!$isCLI) { // If accessed via web, require authentication or disable // For now, we'll allow it but you should add authentication in production header('Content-Type: application/json'); } try { $result = SessionManager::cleanupExpiredImages(); $output = [ 'success' => true, 'message' => "Cleanup completed successfully", 'cleaned_images' => $result['cleaned'], 'errors' => $result['errors'], 'timestamp' => $result['timestamp'] ]; if ($isCLI) { echo "=== Image Cleanup Report ===\n"; echo "Timestamp: {$result['timestamp']}\n"; echo "Images cleaned: {$result['cleaned']}\n"; if (!empty($result['errors'])) { echo "Errors encountered: " . count($result['errors']) . "\n"; foreach ($result['errors'] as $error) { echo " - $error\n"; } } echo "===========================\n\n"; } else { echo json_encode($output, JSON_PRETTY_PRINT); } exit(0); } catch (Exception $e) { $output = [ 'success' => false, 'error' => $e->getMessage(), 'timestamp' => date('Y-m-d H:i:s') ]; if ($isCLI) { echo "ERROR: {$e->getMessage()}\n"; exit(1); } else { http_response_code(500); echo json_encode($output, JSON_PRETTY_PRINT); exit(1); } }