使用LINUX raspbian创建FPDF时发生内部服务器错误

时间:2019-01-28 05:47:32

标签: php linux raspberry-pi3 fpdf internal-server-error

我正在尝试使用FPDF在raspberry-pi中制作PDF,但是下面出现此错误:

我尝试使用chmod将权限更新为755, 这是我的代码:

<?php
$curDate=date("m/d/y");
$pdfDate=date("mdy");
$aveTime='';

require('fpdf.php');
//Connect to your database
$conn=mysqli_connect("localhost","root","password","queuingsystem");

//Create new pdf file
$pdf=new FPDF('P','pt','Letter');

//Disable automatic page break
$pdf->SetAutoPageBreak(false);

//Add first page
$pdf->AddPage();

$pdf->SetFont('Arial','B',30);
$pdf->SetX(25);
$pdf->Cell(560,100,'ENLISTMENT',0,0,'C');
$pdf->Ln(72);
$pdf->SetFont('Arial','',15);
$pdf->SetX(25);
$pdf->Cell(140, 20, 'Date: '. $curDate ,0, 0, 'L');


//set initial y axis position per page
$y_axis_initial = 130;
//Set Row Height
$row_height = 20;

//print column titles
$pdf->SetFillColor(0, 255, 0);
$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($y_axis_initial);
$pdf->SetX(25);
$pdf->Cell(140, 20, 'Student ID', 1, 0, 'C', 1);
$pdf->Cell(140, 20, 'TimeIn', 1, 0, 'C', 1);
$pdf->Cell(140, 20, 'TimeOut', 1, 0, 'C', 1);
$pdf->Cell(140, 20, 'TimeSpent', 1, 0, 'C', 1);

$y_axis = $y_axis_initial + $row_height;

//Select the Products you want to show in your PDF file
$queryGet='select studID,TimeIn,TimeOut,TimeSpent from     tbl_enlistmentlogs WHERE date=CURDATE() AND Status=2';
$result=mysqli_query($conn,$queryGet);
$rowCount=mysqli_num_rows($result);
//initialize counter
$i = 0;

//Set maximum rows per page
$max = 25;


if($rowCount==0){
$pdf->SetFont('Arial','B',30);
$pdf->SetX(25);
$pdf->Cell(560,100,'No Records found!',0,0,'C');
}
else{

while($row = mysqli_fetch_array($result))
{
//If the current row is the last one, create new page and print     column title
if ($i == $max)
{
    $pdf->AddPage();

    //print column titles for the current page
    $pdf->SetFillColor(0, 255, 0);
    $pdf->SetFont('Arial', 'B', 12);
    $pdf->SetY($y_axis_initial);
    $pdf->SetX(25);
    $pdf->Cell(140, 20, 'Student ID', 1, 0, 'C', 1);
    $pdf->Cell(140, 20, 'TimeIn', 1, 0, 'C', 1);
    $pdf->Cell(140, 20, 'TimeOut', 1, 0, 'C', 1);
    $pdf->Cell(140, 20, 'TimeSpent', 1, 0, 'C', 1);

    //Go to next row
    $y_axis = $y_axis + $row_height;

    //Set $i variable to 0 (first row)
    $i = 0;
}

$StudentID = $row['studID'];
$TimeIn = $row['TimeIn'];
$TimeOut = $row['TimeOut'];
$TimeSpent = $row['TimeSpent'];
$pdf->SetFillColor(232, 232, 232);
$pdf->SetFont('Arial','', 12);
$pdf->SetY($y_axis);
$pdf->SetX(25);
$pdf->Cell(140, 20, $StudentID, 1, 0, 'C', 1);
$pdf->Cell(140, 20, $TimeIn, 1, 0, 'C', 1);
$pdf->Cell(140, 20, $TimeOut, 1, 0, 'C', 1);
$pdf->Cell(140, 20, $TimeSpent, 1, 0, 'C', 1);

//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}
$queryAve='SELECT SEC_TO_TIME ( AVG ( TIMESTAMPDIFF ( SECOND, `TimeIn`,`TimeOut`))) FROM tbl_enlistmentlogs WHERE date=CURDATE() AND Status=2';
$ave=mysqli_query($conn,$queryAve);
$row = mysqli_fetch_array($ave);
$aveTime=$row[0];
$pdf->Ln(20);
$pdf->SetFillColor(255, 255, 0);
$pdf->SetFont('Arial','B', 12);
$pdf->SetX(25);
$pdf->Cell(420, 20, 'THE AVERAGE TIME SPENT BY STUDENT', 1, 0, 'C', 1);
$pdf->Cell(140, 20, $aveTime, 1, 0, 'C', 1);

}
mysqli_close($conn);
//Save file
$filee=$pdf->Output('EnlistmentReport'.$pdfDate.'.pdf','F');
$pdf->Output();

?>

这是error.log提供的错误。

  

PHP致命错误:未捕获的异常:FPDF错误:某些数据具有   已经输出,无法发送PDF文件   /var/www/html/fpdf.php:271\n堆栈跟踪:\ n#0
  /var/www/html/fpdf.php(1063):FPDF->错误(“某些数据有一个...”)\ n#1
  /var/www/html/fpdf.php(999):FPDF->_checkoutput()\n#2
  /var/www/html/testFpdf.php(116):FPDF-> Output()\ n#3 {main} \ n
  在第271行的/var/www/html/fpdf.php中抛出

在Windows中,它将预览pdf文件,没有任何错误。

0 个答案:

没有答案