library error: tcpdf Some data has already been output, can not send PDF file

0

I'm having an error in my code

<?php

require_once "../../controllers/gestorsuscriptores.php";
require_once "../../models/gestorsuscriptores.php";

require_once('tcpdf_include.php');

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->AddPage();

$html = <<<EOF

  <img src="images/logo_example.jpg" style="width:300px">
EOF;

$pdf->writeHTML($html, false, false, false, false, '');

$pdf->Output('pdf.pdf', 'I');

?>

The problem that I find is that when I write the code

require_once "../../controllers/gestorsuscriptores.php";
require_once "../../models/gestorsuscriptores.php";

I get the error of: TCPDF ERROR: Some data has already been output, can not send PDF file

THE ARCHIVES I HAVE IN THE FOLDERS, THIS WAY

WHEN I WRITE THE FIRST CODE LINE, IT DOES NOT GIVE ME ANY ERROR

require_once "../../controllers/gestorsuscriptores.php";

BUT WHEN WRITING THE SECOND, IT IS WHERE THE ERROR JUMPS

require_once "../../models/gestorsuscriptores.php";

TCPDF ERROR: Some data has already been output, can not send PDF file

AND IF I JUST WRITE THE SECOND CODE WITHOUT THE FIRST, IT WILL ALSO GIVE ERROR

THE FILE CODE gestorsuscriptores.php IS THIS:

<?php 
require_once 'conexion.php'; 
class SuscriptoresModel
{
    #MOSTRAR SUSCRIPTORES EN LA VISTA
    #------------------------------------------------------------------------------
    public function mostrarSuscriptoresModel($tabla)
    {
        $stmt = Conexion::conectar()->prepare("SELECT id, nombre, email FROM $tabla");
        $stmt -> execute();
        return $stmt -> fetchAll();
        $stmt -> close();
    }

    #BORRAR SUSCRIPTORES
    #------------------------------------------------------------------------------
    public function borrarSuscriptoresModel($datosModel,$tabla)
    {
        $stmt = Conexion::conectar()->prepare("DELETE FROM $tabla WHERE id = :id");
        $stmt->bindParam(":id", $datosModel, PDO::PARAM_INT);
        if ($stmt->execute()) 
        {
            return "ok";
        }
        else
        {
            return "error";
        }
        $stmt->close();
    }
}

I REALLY DO NOT KNOW WHAT'S HAPPENING I HOPE AND CAN ANSWER AND IN ADVANCE MANY THANKS

    
asked by Grsn Chml 20.08.2018 в 21:59
source

1 answer

0

ACHIEVE TO SOLVE IT WITH THE FOLLOWING CODE

ob_end_clean();

THAT CODE MUST BE ADDED BEFORE:

$pdf->Output('pdf.pdf', 'I');

WHICH FOUND HIM IN:

link

SERVE TO: Clean (delete) the output buffer and disable storage in it

link

    
answered by 20.08.2018 / 22:28
source