Path : /home/vishqocm/pcib.in/admin/
File Upload :
Current File : /home/vishqocm/pcib.in/admin/check_profile_image.php

<?php
// Start session if not already started
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || ($_SESSION['role'] !== 'admin' && $_SESSION['role'] !== 'director')) {
    header('Location: login.php');
    exit();
}

require_once 'database/db_config.php';

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Check Profile Image</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        pre { background: #f4f4f4; padding: 10px; }
        .avatar { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; border: 2px solid #4e73df; }
    </style>
</head>
<body>
    <h1>Profile Image Check</h1>
    
    <?php
    // Display session data
    echo "<h2>Session Data:</h2>";
    echo "<pre>";
    print_r($_SESSION);
    echo "</pre>";
    
    // Check user profile image in database
    if (isset($_SESSION['user_id'])) {
        $userId = $_SESSION['user_id'];
        $stmt = $conn->prepare("SELECT username, email, profile_image FROM users WHERE id = ?");
        $stmt->bind_param("i", $userId);
        $stmt->execute();
        $result = $stmt->get_result();
        
        if ($row = $result->fetch_assoc()) {
            echo "<h2>User Data from Database:</h2>";
            echo "<p><strong>Username:</strong> " . htmlspecialchars($row['username']) . "</p>";
            echo "<p><strong>Email:</strong> " . htmlspecialchars($row['email']) . "</p>";
            
            if (!empty($row['profile_image'])) {
                echo "<p><strong>Raw Profile Image Path:</strong> " . htmlspecialchars($row['profile_image']) . "</p>";
                
                // Check if path exists
                $fullPath = '../' . $row['profile_image'];
                echo "<p><strong>Full Path to Check:</strong> " . htmlspecialchars($fullPath) . "</p>";
                echo "<p><strong>File Exists:</strong> " . (file_exists($fullPath) ? 'Yes' : 'No') . "</p>";
                
                // Display image with different path formats
                echo "<h3>Image Display Tests:</h3>";
                
                echo "<p>Direct from database (../ prefix):</p>";
                echo "<img src='../" . htmlspecialchars($row['profile_image']) . "' alt='User Avatar' class='avatar'>";
                
                echo "<p>With ../ prefix removed if present:</p>";
                $relPath = $row['profile_image'];
                if (strpos($relPath, '../') === 0) {
                    $relPath = substr($relPath, 3);
                }
                echo "<img src='../" . htmlspecialchars($relPath) . "' alt='User Avatar' class='avatar'>";
                
                echo "<p>Relative to root:</p>";
                echo "<img src='/" . htmlspecialchars($relPath) . "' alt='User Avatar' class='avatar'>";
            } else {
                echo "<p><strong>Profile Image:</strong> No image found in database</p>";
                echo "<img src='../assets/img/default-avatar.png' alt='Default Avatar' class='avatar'>";
            }
        } else {
            echo "<p>No user found with ID " . htmlspecialchars($userId) . "</p>";
        }
        $stmt->close();
    } else {
        echo "<p>No user_id found in session.</p>";
    }
    ?>
    
    <h2>Back to Admin Panel</h2>
    <p><a href="index.php">Return to Dashboard</a></p>
</body>
</html>