File "verComprobante.php"

Full Path: C:/wamp64/www/RegistroEquipos2/backend/envios/verComprobante.php
File size: 1.16 KB
MIME-type: text/x-php
Charset: utf-8

<?php
session_start();
$host = '192.200.100.40';
$db = 'sistemas';
$user = 'SANMARINO';
$pass = 'sanmarino2021*';
$charset = 'utf8mb4';

if (!isset($_GET['id']) || empty($_GET['id'])) {
    die('ID no proporcionado');
}
$id = intval($_GET['id']);

try {
    $pdo = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]);

    // Nombre de tabla corregido: registrosenvios
    $sql = "SELECT pdf_comprobante FROM registrosenvios WHERE id = :id";
    $stmt = $pdo->prepare($sql);
    $stmt->execute([':id' => $id]);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($row && $row['pdf_comprobante']) {
        header('Content-Type: application/pdf');
        header('Content-Disposition: inline; filename="comprobante_' . $id . '.pdf"');
        header('Cache-Control: private, max-age=0, must-revalidate');
        header('Pragma: public');
        echo $row['pdf_comprobante'];
        exit;
    } else {
        echo "No hay comprobante para este registro o el registro no existe.";
    }
} catch (PDOException $e) {
    echo "Error en la base de datos: " . $e->getMessage();
}