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

查看:52
本文介绍了FPDF错误:已经输出了一些数据,无法在000webhost上发送PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FPDF类在我的网站上生成pdf.一切正常,直到最近几周我开始出现错误:

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

在过去的几周中,我的代码没有任何变化,并且我还检查了fpdf的输出是否执行过fpdf(包括php之前的多余空格,禁用了BOM签名等)

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

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

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

是否可以通过php禁用网页上的任何其他输出?还是有人在000webhost上使用fpdf?

Is there a way to disable any other output on web page by php? or does someone use fpdf on 000webhost?

推荐答案

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

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

如果将session.auto_start设置为0无效,请尝试以下操作:

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

这篇关于FPDF错误:已经输出了一些数据,无法在000webhost上发送PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆