php FPDF错误:部分数据已经输出,无法在000webhost上发送PDF文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18172440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FPDF error: Some data has already been output, can't send PDF file on 000webhost
提问by user1857756
I am using FPDF class to generate a pdf on my website. Everything worked well until last few weeks when I started getting error:
我正在使用 FPDF 类在我的网站上生成 pdf。直到最近几周我开始出现错误时,一切都运行良好:
?FPDF error: Some data has already been output, can't send PDF file
During last few weeks haven't change anything in my code and I have also checked for any output execpt the fpdf (including unecessary space before php, disabled BOM signature etc.)
在过去的几周里,我的代码没有任何变化,我还检查了 fpdf 的任何输出(包括 php 之前的不必要空间、禁用的 BOM 签名等)
I have my website on 000webhost.com so I have also disabled the analytic code at the end of the page, but the pdf still doesn't work. The only trace I have left is misterious "" in a source code (I can see it when checking source code in Chrome browser).
我在 000webhost.com 上有我的网站,所以我也禁用了页面末尾的分析代码,但 pdf 仍然不起作用。我留下的唯一痕迹是源代码中的神秘“”(我在 Chrome 浏览器中检查源代码时可以看到它)。
I cant get to work even this simple example:
即使是这个简单的例子,我也无法开始工作:
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage()
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
Is there a way to disable any other output on web page by php? or does someone use fpdf on 000webhost?
有没有办法通过php禁用网页上的任何其他输出?或者有人在 000webhost 上使用 fpdf 吗?
回答by user1825831
just insert ob_end_clean(); before outputing.
只需插入 ob_end_clean(); 在输出之前。
<?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();
?>
回答by 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.
我认为session.auto_start
设置为 1。这将启动一个会话并向PHPSESSID
浏览器发送一个cookie。
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:
如果设置session.auto_start
为 0 不起作用,请尝试以下操作:
<?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();
?>
回答by Victor
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.
当我提出生成报告的请求时,浏览器中显示了一些警告(如使用已弃用的功能)。
谈到off
该display_errors
选项后,已成功生成报告。
回答by abid saleem
Use line like this:
使用这样的行:
require('fpdf.php'); ob_end_clean(); header("Content-Encoding: None", true);
Issue will resolved ;)
问题将得到解决;)
回答by Lapochka
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:
如果您已经在该浏览器页面上呈现其他内容后尝试生成 PDF,则会发生此错误,例如,如果您执行了以下操作:
echo $value;
回声 $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).
FPDF 代码需要一个“空白画布”来呈现其输出(或者,一个空白的 iframe,尽管我还没有测试过)。
回答by 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.
错误:部分数据已输出,无法发送PDF文件。
回答by Wellington Telles Cunha
I putted this to fix this problem in the beggining (ob_clean) doesn't change PDF structure:
我把它放在开始解决这个问题(ob_clean)不会改变PDF结构:
require('fpdf/fpdf.php');
ob_clean();