FPDF error: Some data has already been output, can't send PDF file on 000webhost

☆樱花仙子☆ 提交于 2019-11-30 22:10:58
Raymond Nijland

I think that session.auto_start is set to 1. This will start a session and send a PHPSESSID cookie to the browser.

You can try to disable it using the following code:

<?php
ini_set("session.auto_start", 0);
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage()
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

In case setting session.auto_start to 0 does not work, then try this:

<?php
ob_start();
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage()
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
ob_end_flush(); 
?>

just insert ob_end_clean(); before outputing.

<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage()
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
ob_end_clean();
$pdf->Output();
?>

In my case i had set:

ini_set('display_errors', 'on');
error_reporting(E_ALL | E_STRICT);

When i made the request to generate the report, some warnings were displayed in the browser (like the usage of deprecated functions).
Turning off the display_errors option, the report was generated successfully.

abid saleem

Use line like this:

require('fpdf.php');    ob_end_clean();    header("Content-Encoding: None", true);

Issue will resolved ;)

This error will occur if you try to generate the PDF after you have already rendered something else on that browser page, for example, if you have done something like this:

echo $value;

The FPDF code wants a "blank canvas" to render its output on (or, one surmises, a blank iframe, although I haven't tested that yet).

Juan Pablo
SELECT motivo, 
       unidad_trans, 
       km_inicial, 
       km_final, 
       rut_chofer, 
       To_char(hora_inicial, 'DD/MM/YYYY HH:mm'), 
       To_char(hora_final, 'DD/MM/YYYY HH:mm'), 
       total_recorrido, 
       destino, 
       cod_combustible, 
       cantidad_litros, 
       cod_vehiculo, 
       d.cod_estableci 
FROM   mov_bitacora b, 
       mov_chofer c, 
       nuc_dependencias d, 
       mov_combustible co, 
       mov_vehiculo v 
WHERE  b.unidad_tran = d.cod_estableci 
       AND b.rut_chofer = c.rut_chofer 
       AND b.cod_combustible = co.cod_combustible 
       AND b.cod_vehiculo = v.cod_vehiculo 
       AND id_bitacora = 6fpdf 

Error: Some data has already been output, can't send PDF file.

I putted this to fix this problem in the beggining (ob_clean) doesn't change PDF structure:

require('fpdf/fpdf.php');
ob_clean();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!