![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/public_html/ |
<?php
/**
* Diagnostic tool to check profile image values in database
* Usage: /check_profile_image.php?user=ulysse or /check_profile_image.php?user_id=123
*/
session_start();
require_once 'config/database.php';
// Check if user is admin
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
die('Admin access required');
}
$pdo = getDBConnection();
$username = $_GET['user'] ?? '';
$user_id = $_GET['user_id'] ?? null;
if ($username) {
$stmt = $pdo->prepare("SELECT id, name FROM users WHERE LOWER(name) = LOWER(?)");
$stmt->execute([$username]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user) {
$user_id = $user['id'];
}
}
if (!$user_id) {
die('User not found. Use ?user=username or ?user_id=123');
}
// Get profile image from both tables
$stmt = $pdo->prepare("
SELECT
u.id,
u.name,
u.profile_image as users_profile_image,
up.profile_image as user_profiles_profile_image,
COALESCE(NULLIF(up.profile_image, ''), NULLIF(u.profile_image, ''), NULL) as combined_profile_image
FROM users u
LEFT JOIN user_profiles up ON u.id = up.user_id
WHERE u.id = ?
");
$stmt->execute([$user_id]);
$data = $stmt->fetch(PDO::FETCH_ASSOC);
echo "<h2>Profile Image Diagnostic for: {$data['name']} (ID: {$data['id']})</h2>";
echo "<pre>";
echo "users.profile_image: " . var_export($data['users_profile_image'], true) . "\n";
echo "user_profiles.profile_image: " . var_export($data['user_profiles_profile_image'], true) . "\n";
echo "Combined (COALESCE): " . var_export($data['combined_profile_image'], true) . "\n";
echo "\n";
// Check if file exists
if (!empty($data['combined_profile_image']) && strpos($data['combined_profile_image'], '/') === 0) {
$filePath = $_SERVER['DOCUMENT_ROOT'] . $data['combined_profile_image'];
echo "File path: " . htmlspecialchars($filePath) . "\n";
echo "File exists: " . (file_exists($filePath) ? 'YES' : 'NO') . "\n";
if (file_exists($filePath)) {
echo "File size: " . filesize($filePath) . " bytes\n";
echo "Is file: " . (is_file($filePath) ? 'YES' : 'NO') . "\n";
}
}
echo "</pre>";
// Test formatProfileImage function
if (!function_exists('formatProfileImage')) {
function formatProfileImage($profile_image, $name) {
if ($profile_image === null || $profile_image === false) {
return null;
}
$profile_image = trim((string)$profile_image);
if (empty($profile_image) || $profile_image === 'null' || $profile_image === 'NULL' || $profile_image === '') {
return null;
}
if (preg_match('/^https?:\/\//i', $profile_image)) {
return $profile_image;
}
if (strpos($profile_image, '/') === 0) {
if (preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $profile_image)) {
return $profile_image;
}
if (strpos($profile_image, '/uploads/') === 0 || strpos($profile_image, '/profile') === 0) {
return $profile_image;
}
}
if (preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $profile_image)) {
if (strpos($profile_image, 'uploads/') !== false || strpos($profile_image, 'profile') !== false) {
if (strpos($profile_image, '/') === false) {
return '/uploads/profile_images/' . $profile_image;
} else {
return '/' . ltrim($profile_image, '/');
}
}
}
return null;
}
}
$formatted = formatProfileImage($data['combined_profile_image'], $data['name']);
echo "<h3>After formatProfileImage:</h3>";
echo "<pre>";
echo "Result: " . var_export($formatted, true) . "\n";
echo "Should show placeholder: " . (empty($formatted) ? 'YES' : 'NO') . "\n";
echo "</pre>";
?>