PHP: FPDF 文件在在线服务器中出错?
PHP: FPDF file is giving error in online server?
我创建的 fpdf 文件在本地主机上运行良好,但是当我上传到在线服务器时,它没有显示并显示 error。
Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Some data has already been output, can't send PDF file (output started at /home/usapaystubs717/public_html/stub/stub.php:1)' in /home/usapaystubs717/public_html/stub/fpdf.php:271 Stack trace: #0 /home/usapaystubs717/public_html/stub/fpdf.php(1040): FPDF->Error('Some data has a...') #1 /home/usapaystubs717/public_html/stub/fpdf.php(987): FPDF->_checkoutput() #2 /home/usapaystubs717/public_html/stub/stub.php(213): FPDF->Output() #3 {main} thrown in /home/usapaystubs717/public_html/stub/fpdf.php on line 271
这是代码
<?php
require('fpdf.php');
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$address = $_POST['address'];
}
$pdf = new FPDF();
$pdf->AddPage();
/*$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');*/
// 20mm from each edge
$pdf->SetFont('Arial','B',16);
/*$pdf->MultiCell(95,6,"Pakistan",'BB');*/
$pdf->Cell(0,10,"Welcome ",3,0,'L');
$pdf->SetFont('Arial', '', 15);
$pdf->SetXY(160 , 30);
$pdf->Write(10, "May 8, 2016");
$pdf->Line(18, 45, 210-20, 45);
$pdf->SetFont('Arial', 'B', 10);
$pdf->SetXY(10 , 54);
$pdf->Write(10, "PAY");
$pdf->SetFont('Arial', '', 11);
$pdf->SetXY(18.5 , 54);
$pdf->Write(10, "ONE THOUSAND TWO HUNDRED THIRTY");
/*$pdf->SetXY(110, 30);
$pdf->MultiCell(95,6,"Pakistan",'BB','R');*/
$pdf->SetXY(18 , 75);
$pdf->Cell(35,10,"Pay to the order of ",1,0,'C');
$pdf->SetXY(55, 79);
$pdf->MultiCell(95,6,"Zain Farooq",'BB','L');
/*$pdf->Line(20, 45, 210-20, 45);
$pdf->Line(50, 45, 210-50, 45);*/
$pdf->Ln();
$pdf->SetFont('Arial','',10);
$pdf->setFillColor(0,0,0);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(80, 6, 'COMPANY INFORMATION', 1,0,'C',1);
$pdf->SetFont('Arial','',18);
$pdf->SetTextColor(0,0,0);
$pdf->setFillColor(230,230,230);
$pdf->Cell(80, 23, 'Earnings statement', 1 ,0,'C',1);
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 97);
$pdf->SetTextColor(0,0,0);
$pdf->MultiCell(80, 17, 'Extra statements', 'BL' ,'L');
$pdf->SetXY(10 , 103);
$pdf->MultiCell(90,11,"",'BL','R');
/*$pdf->Cell(80, 11, 'Extra statements', 1 ,0,'UL');*/
/*$pdf->Cell(50, 6, 'Itinerary', 1);
$pdf->Cell(19.75, 6, 'ETD', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'ETA', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'Block', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'Waiting', 1, 0, 'C');*/
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 114);
$pdf->setFillColor(0,0,0);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(80, 6, 'Employee Information', 1,0,'C',1);
$pdf->Cell(40, 6, 'Social Security', 1,0,'C',1);
$pdf->Cell(40, 6, 'Employee ID', 1, 0, 'C',1);
$pdf->Ln();
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(10 , 114);
$pdf->Cell(80, 18, '4323', 1);
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(90 , 120);
$pdf->setFillColor(255,255,255);
$pdf->Cell(40, 4, 'XXX-XX-123', 1,0,'C',1);
$pdf->Cell(40, 4, '123456', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(90 , 124);
$pdf->setFillColor(0,0,0);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(20, 4, 'Start Date', 1,0,'C',1);
$pdf->Cell(20, 4, 'End Date', 1, 0, 'C',1);
$pdf->Cell(40, 4, 'Check Date', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(90 , 128);
$pdf->setFillColor(255,255,255);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(20, 4, 'Start Date', 1,0,'C',1);
$pdf->Cell(20, 4, 'End Date', 1, 0, 'C',1);
$pdf->Cell(40, 4, 'Check Date', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 132.3);
$pdf->setFillColor(0,0,0);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(20, 6, 'Earnings', 1,0,'C',1);
$pdf->Cell(20,6, 'Rate', 1, 0, 'C',1);
$pdf->Cell(20,6, 'Hours', 1, 0, 'C',1);
$pdf->Cell(20, 6, 'Current', 1,0,'C',1);
$pdf->Cell(20, 6, 'Year to date', 1, 0, 'C',1);
$pdf->Cell(20, 6, 'Deductions', 1, 0, 'C',1);
$pdf->Cell(20, 6, 'Current', 1,0,'C',1);
$pdf->Cell(20, 6, 'Year to date', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 137.3);
$pdf->setFillColor(255,255,255);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(20, 50, 'Earnings', 1,0,'T',1);
$pdf->Cell(20,50, 'Rate', 1, 0, 'C',1);
$pdf->Cell(20,50, 'Hours', 1, 0, 'C',1);
$pdf->Cell(20, 50, 'Current', 1,0,'C',1);
$pdf->Cell(20, 50, 'Year to date', 1, 0, 'C',1);
$pdf->Cell(20, 50, 'Deductions', 1, 0, 'C',1);
$pdf->Cell(20, 50, 'Current', 1,0,'C',1);
$pdf->Cell(20, 50, 'Year to date', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','B',8);
$pdf->SetXY(10 , 187.3);
$pdf->setFillColor(230,230,230);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(60, 6, 'Earnings', 1,0,'R',1);
$pdf->SetFont('Arial','',8);
$pdf->Cell(20, 6, '1600.00', 1,0,'C',1);
$pdf->Cell(20, 6, '14,400.00', 1, 0, 'C',1);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(20, 6, 'Deductions', 1, 0, 'C',1);
$pdf->SetFont('Arial','',8);
$pdf->Cell(20, 6, '370.00', 1,0,'C',1);
$pdf->Cell(20, 6, '3,300.00', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 193.3);
$pdf->setFillColor(255,255,255);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(26.66667, 6, 'Check Number', 1,0,'R',1);
$pdf->Cell(26.66667, 6, '#6059', 1,0,'C',1);
$pdf->Cell(26.66667, 6, 'Net Pay', 1, 0, 'C',1);
$pdf->Cell(26.66667, 6, ',230', 1, 0, 'C',1);
$pdf->Cell(26.66667, 6, 'YTD NET PAY', 1,0,'C',1);
$pdf->Cell(26.66667, 6, ',070', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 199.5);
$pdf->setFillColor(0,0,0);
$pdf->Cell(160, 5, '', 1, 0, '',1);
$pdf->Ln();
/*Output('filename.pdf','D');*/
$pdf->Output();
?>
尝试这样做
<?php
ini_set("session.auto_start", 0);
require('fpdf.php');
或
<?php
ob_start();
require('fpdf.php');
如另一个问题 FPDF error: Some data has already been output, can't send PDF 所述,您应该检查是否已经发送了一些输出。输出可以是 "echo",或者一些标记,甚至是 php 开始标记之前的一些前导 space。从您提供的 link 来看,错误之前似乎有一个空行。
尝试将文件重新编码为没有 BOM 的 UTF-8,这对我有用
我创建的 fpdf 文件在本地主机上运行良好,但是当我上传到在线服务器时,它没有显示并显示 error。
Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Some data has already been output, can't send PDF file (output started at /home/usapaystubs717/public_html/stub/stub.php:1)' in /home/usapaystubs717/public_html/stub/fpdf.php:271 Stack trace: #0 /home/usapaystubs717/public_html/stub/fpdf.php(1040): FPDF->Error('Some data has a...') #1 /home/usapaystubs717/public_html/stub/fpdf.php(987): FPDF->_checkoutput() #2 /home/usapaystubs717/public_html/stub/stub.php(213): FPDF->Output() #3 {main} thrown in /home/usapaystubs717/public_html/stub/fpdf.php on line 271
这是代码
<?php
require('fpdf.php');
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$address = $_POST['address'];
}
$pdf = new FPDF();
$pdf->AddPage();
/*$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');*/
// 20mm from each edge
$pdf->SetFont('Arial','B',16);
/*$pdf->MultiCell(95,6,"Pakistan",'BB');*/
$pdf->Cell(0,10,"Welcome ",3,0,'L');
$pdf->SetFont('Arial', '', 15);
$pdf->SetXY(160 , 30);
$pdf->Write(10, "May 8, 2016");
$pdf->Line(18, 45, 210-20, 45);
$pdf->SetFont('Arial', 'B', 10);
$pdf->SetXY(10 , 54);
$pdf->Write(10, "PAY");
$pdf->SetFont('Arial', '', 11);
$pdf->SetXY(18.5 , 54);
$pdf->Write(10, "ONE THOUSAND TWO HUNDRED THIRTY");
/*$pdf->SetXY(110, 30);
$pdf->MultiCell(95,6,"Pakistan",'BB','R');*/
$pdf->SetXY(18 , 75);
$pdf->Cell(35,10,"Pay to the order of ",1,0,'C');
$pdf->SetXY(55, 79);
$pdf->MultiCell(95,6,"Zain Farooq",'BB','L');
/*$pdf->Line(20, 45, 210-20, 45);
$pdf->Line(50, 45, 210-50, 45);*/
$pdf->Ln();
$pdf->SetFont('Arial','',10);
$pdf->setFillColor(0,0,0);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(80, 6, 'COMPANY INFORMATION', 1,0,'C',1);
$pdf->SetFont('Arial','',18);
$pdf->SetTextColor(0,0,0);
$pdf->setFillColor(230,230,230);
$pdf->Cell(80, 23, 'Earnings statement', 1 ,0,'C',1);
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 97);
$pdf->SetTextColor(0,0,0);
$pdf->MultiCell(80, 17, 'Extra statements', 'BL' ,'L');
$pdf->SetXY(10 , 103);
$pdf->MultiCell(90,11,"",'BL','R');
/*$pdf->Cell(80, 11, 'Extra statements', 1 ,0,'UL');*/
/*$pdf->Cell(50, 6, 'Itinerary', 1);
$pdf->Cell(19.75, 6, 'ETD', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'ETA', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'Block', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'Waiting', 1, 0, 'C');*/
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 114);
$pdf->setFillColor(0,0,0);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(80, 6, 'Employee Information', 1,0,'C',1);
$pdf->Cell(40, 6, 'Social Security', 1,0,'C',1);
$pdf->Cell(40, 6, 'Employee ID', 1, 0, 'C',1);
$pdf->Ln();
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(10 , 114);
$pdf->Cell(80, 18, '4323', 1);
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(90 , 120);
$pdf->setFillColor(255,255,255);
$pdf->Cell(40, 4, 'XXX-XX-123', 1,0,'C',1);
$pdf->Cell(40, 4, '123456', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(90 , 124);
$pdf->setFillColor(0,0,0);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(20, 4, 'Start Date', 1,0,'C',1);
$pdf->Cell(20, 4, 'End Date', 1, 0, 'C',1);
$pdf->Cell(40, 4, 'Check Date', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(90 , 128);
$pdf->setFillColor(255,255,255);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(20, 4, 'Start Date', 1,0,'C',1);
$pdf->Cell(20, 4, 'End Date', 1, 0, 'C',1);
$pdf->Cell(40, 4, 'Check Date', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 132.3);
$pdf->setFillColor(0,0,0);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(20, 6, 'Earnings', 1,0,'C',1);
$pdf->Cell(20,6, 'Rate', 1, 0, 'C',1);
$pdf->Cell(20,6, 'Hours', 1, 0, 'C',1);
$pdf->Cell(20, 6, 'Current', 1,0,'C',1);
$pdf->Cell(20, 6, 'Year to date', 1, 0, 'C',1);
$pdf->Cell(20, 6, 'Deductions', 1, 0, 'C',1);
$pdf->Cell(20, 6, 'Current', 1,0,'C',1);
$pdf->Cell(20, 6, 'Year to date', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 137.3);
$pdf->setFillColor(255,255,255);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(20, 50, 'Earnings', 1,0,'T',1);
$pdf->Cell(20,50, 'Rate', 1, 0, 'C',1);
$pdf->Cell(20,50, 'Hours', 1, 0, 'C',1);
$pdf->Cell(20, 50, 'Current', 1,0,'C',1);
$pdf->Cell(20, 50, 'Year to date', 1, 0, 'C',1);
$pdf->Cell(20, 50, 'Deductions', 1, 0, 'C',1);
$pdf->Cell(20, 50, 'Current', 1,0,'C',1);
$pdf->Cell(20, 50, 'Year to date', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','B',8);
$pdf->SetXY(10 , 187.3);
$pdf->setFillColor(230,230,230);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(60, 6, 'Earnings', 1,0,'R',1);
$pdf->SetFont('Arial','',8);
$pdf->Cell(20, 6, '1600.00', 1,0,'C',1);
$pdf->Cell(20, 6, '14,400.00', 1, 0, 'C',1);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(20, 6, 'Deductions', 1, 0, 'C',1);
$pdf->SetFont('Arial','',8);
$pdf->Cell(20, 6, '370.00', 1,0,'C',1);
$pdf->Cell(20, 6, '3,300.00', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 193.3);
$pdf->setFillColor(255,255,255);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(26.66667, 6, 'Check Number', 1,0,'R',1);
$pdf->Cell(26.66667, 6, '#6059', 1,0,'C',1);
$pdf->Cell(26.66667, 6, 'Net Pay', 1, 0, 'C',1);
$pdf->Cell(26.66667, 6, ',230', 1, 0, 'C',1);
$pdf->Cell(26.66667, 6, 'YTD NET PAY', 1,0,'C',1);
$pdf->Cell(26.66667, 6, ',070', 1, 0, 'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->SetXY(10 , 199.5);
$pdf->setFillColor(0,0,0);
$pdf->Cell(160, 5, '', 1, 0, '',1);
$pdf->Ln();
/*Output('filename.pdf','D');*/
$pdf->Output();
?>
尝试这样做
<?php
ini_set("session.auto_start", 0);
require('fpdf.php');
或
<?php
ob_start();
require('fpdf.php');
如另一个问题 FPDF error: Some data has already been output, can't send PDF 所述,您应该检查是否已经发送了一些输出。输出可以是 "echo",或者一些标记,甚至是 php 开始标记之前的一些前导 space。从您提供的 link 来看,错误之前似乎有一个空行。
尝试将文件重新编码为没有 BOM 的 UTF-8,这对我有用