51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
// avatar.php
|
|
session_start();
|
|
require_once 'config/db.php';
|
|
|
|
// Get CID from GET parameter or fallback to session
|
|
$cid = $_GET['cid'] ?? ($_SESSION['cid'] ?? '');
|
|
$name = $_GET['name'] ?? ($_SESSION['fullname'] ?? 'User');
|
|
|
|
$fallback_url = 'https://ui-avatars.com/api/?name=' . urlencode($name) . '&background=0F766E&color=fff';
|
|
|
|
if (empty($cid)) {
|
|
header('Location: ' . $fallback_url);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = $pdo_hos->prepare("SELECT HR_IMAGE FROM hr_person WHERE HR_CID = :cid LIMIT 1");
|
|
$stmt->execute(['cid' => $cid]);
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($row && !empty($row['HR_IMAGE'])) {
|
|
// We have an image blob
|
|
$image_data = $row['HR_IMAGE'];
|
|
|
|
// Output appropriate headers
|
|
// Assuming it's typically JPEG or PNG. Use finfo to get mime if possible, or fallback to jpeg.
|
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
|
$mime = $finfo->buffer($image_data);
|
|
|
|
if (!$mime || $mime == 'application/octet-stream') {
|
|
$mime = 'image/jpeg';
|
|
}
|
|
|
|
header("Content-Type: " . $mime);
|
|
header("Content-Length: " . strlen($image_data));
|
|
// Add caching headers
|
|
header("Cache-Control: public, max-age=86400");
|
|
|
|
echo $image_data;
|
|
exit;
|
|
}
|
|
} catch (PDOException $e) {
|
|
// Silently fallback on database error
|
|
}
|
|
|
|
// If no image found or error, redirect to ui-avatars
|
|
header('Location: ' . $fallback_url);
|
|
exit;
|
|
?>
|