我正在使用FPDF类在我的网站上生成pdf.在我开始收到错误的最后几周,一切运作良好:
?FPDF error: Some data has already been output, can't send PDF file
Run Code Online (Sandbox Code Playgroud)
在过去的几周里,我的代码中没有任何改变,我也检查过任何输出execpt 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();
?>
Run Code Online (Sandbox Code Playgroud)
有没有办法通过PHP禁用网页上的任何其他输出?或者有人在000webhost上使用fpdf吗?
use*_*831 23
只需插入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();
?>
Run Code Online (Sandbox Code Playgroud)
Ray*_*and 11
我认为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();
?>
Run Code Online (Sandbox Code Playgroud)
如果设置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();
?>
Run Code Online (Sandbox Code Playgroud)