FPDF错误。某些数据已被输出,无法在000webhost上发送PDF文件[英] FPDF error: Some data has already been output, can't send PDF file on 000webhost

本文是小编为大家收集整理的关于FPDF错误。某些数据已被输出,无法在000webhost上发送PDF文件的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在使用FPDF类在我的网站上生成PDF.一切效果都很好,直到我开始遇到错误的最后几周:

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

在过去的几周中,我的代码没有更改任何内容,我还检查了任何输出执行FPDF(包括PHP之前不必要的空间,残疾BOM签名等)

)

我在000webhost.com上有我的网站,因此我在页面末尾也禁用了分析代码,但是PDF仍然不起作用.我剩下的唯一的跟踪是源代码中的""(在Chrome浏览器中检查源代码时我可以看到它).

我甚至无法上班这个简单的例子:

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

有没有办法通过PHP禁用网页上的任何其他输出?还是有人在000webhost上使用FPDF?

推荐答案

我认为session.auto_start设置为1.这将启动会话并将PHPSESSID cookie发送到浏览器.

您可以尝试使用以下代码将其禁用:

<?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();
?>

如果设置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(); 
?>

其他推荐答案

只需插入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();
?>

其他推荐答案

在我的情况下,我已经设置了:

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

当我提出生成报告的请求时,在浏览器中显示了一些警告(例如,不推荐的功能的使用).
turning off display_errors选项,该报告成功生成.

本文地址:https://www.itbaoku.cn/post/2090887.html

问题描述

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 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.)

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).

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?

推荐答案

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.