where('id', $id); qr_apply_owner_scope($db); $row = $db->getOne("{$type}_qrcodes"); if ($row === null) { http_response_code(404); exit('Not found'); } $path = SAVED_QRCODE_DIRECTORY . $row['qrcode']; if (!is_file($path)) { http_response_code(404); exit('Not found'); } $mime_types = [ 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'svg' => 'image/svg+xml', 'eps' => 'application/postscript', ]; $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION)); $mime = $mime_types[$extension] ?? 'application/octet-stream'; $is_download = isset($_GET['download']) && $_GET['download'] === '1'; header('Content-Type: ' . $mime); header('Content-Length: ' . filesize($path)); header('Cache-Control: private, max-age=0, no-cache'); header('Content-Disposition: ' . ($is_download ? 'attachment' : 'inline') . '; filename="' . basename($path) . '"'); readfile($path); exit;