<?php
/**
 * Test Router - Debug routing issues
 */

echo "<h1>Router Test</h1>";
echo "<p>Request URI: " . htmlspecialchars($_SERVER['REQUEST_URI']) . "</p>";

$requestPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
echo "<p>Parsed Path: " . htmlspecialchars($requestPath) . "</p>";

$requestPath = ltrim($requestPath, '/');
echo "<p>After ltrim: " . htmlspecialchars($requestPath) . "</p>";

if (strpos($requestPath, 'backend/') === 0) {
    $requestPath = substr($requestPath, 8);
    echo "<p>After stripping 'backend/': " . htmlspecialchars($requestPath) . "</p>";
}

if (strpos($requestPath, 'uploads/') === 0) {
    $uploadRelativePath = substr($requestPath, 8);
    $uploadFile = __DIR__ . '/uploads/' . $uploadRelativePath;
    echo "<p>Upload relative path: " . htmlspecialchars($uploadRelativePath) . "</p>";
    echo "<p>Full file path: " . htmlspecialchars($uploadFile) . "</p>";
    echo "<p>File exists: " . (file_exists($uploadFile) ? 'YES' : 'NO') . "</p>";
    if (file_exists($uploadFile)) {
        echo "<p>File size: " . filesize($uploadFile) . " bytes</p>";
    }
}

if (strpos($requestPath, 'admin/') === 0 || $requestPath === 'admin') {
    echo "<p>Admin route detected!</p>";
    $adminPath = str_replace('admin/', '', $requestPath);
    $adminPath = ltrim($adminPath, '/');
    echo "<p>Admin path: " . htmlspecialchars($adminPath) . "</p>";
    $adminFile = __DIR__ . '/admin/index.php';
    echo "<p>Admin index exists: " . (file_exists($adminFile) ? 'YES' : 'NO') . "</p>";
}

echo "<hr>";
echo "<h2>Test Links:</h2>";
echo "<ul>";
echo "<li><a href='/backend/admin/'>Admin Panel</a></li>";
echo "<li><a href='/backend/uploads/technology/693ab7769594d_1765455734.jpg'>Test Image</a></li>";
echo "<li><a href='/backend/uploads/gallery/693a9159db135_1765445977.jpg'>Gallery Image</a></li>";
echo "</ul>";

