简体   繁体   English

致命错误:未捕获异常:FPDF 错误:一些数据已经是 output,无法发送 PDF 文件(输出开始于

[英]Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file (output started at

I am generating a PDF file based on the selected employee ID i was facing an error on the local system while still in development saying that Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file (output started at the/path)我正在根据选定的员工 ID 生成 PDF 文件,我在开发过程中在本地系统上遇到错误,说致命错误:未捕获的异常:FPDF 错误:某些数据已经是 output,无法发送 ZBCD1B686137759B 文件输出开始于/路径)

And then i added these two lines to the php script and it worked fine然后我将这两行添加到 php 脚本中,它运行良好

ob_start();

and at the end最后

ob_end_flush();

But after hosting it to the live server the error is thrown again但是在将其托管到实时服务器后,再次引发错误

Have reffered the FPDF documn** ob_end_clean();已参考 FPDF 文档** ob_end_clean(); ** on the beginning of the php script Documentation Link ** 开头的 php 脚本文档链接

The complete code for this is as follows,完整的代码如下,

The empleavehis.php page empleavehis.php 页面

<?php
if (isset($_POST['pdfemployeeleave'])) {
ob_start();
require('mysql_table.php');

$link = mysqli_connect('localhost','root','','hr');
$empidinfo=$_REQUEST['empid'];

class PDF extends PDF_MySQL_Table
{
    function Header()
    {
    // Title
        $this->Image('img/prudentialshippinglines.png',15,6,15);
        $this->SetFont('Arial','',18);
        $this->Cell(0,6,'Short Summary ',0,1,'C');
        $this->Cell(0,6,' ',0,1,'C');
        $this->SetFont('Arial','',15);
        $this->Cell(0,6,'History Of Leaves Taken By The Employee',0,1,'C');
        $this->Ln(10);
    // Ensure table header is printed
        parent::Header();
    }
}

// Connect to database

$pdf = new PDF('L','mm','A4');


//$pdf->AddPage();
// First table: output all columns
// $pdf->Table($link,'select * from employees where EMP_ID = 1');
$pdf->AddPage();
// Second table: specify 3 columns
$pdf->AddCol('Leave_Type',48,'Type');
$pdf->AddCol('LeaveSub_Type',48,'Sub Type');
$pdf->AddCol('Start',48,'Start');
$pdf->AddCol('End',48,'End');
$pdf->AddCol('Remarks',48,'Remarks');
$pdf->AddCol('Status',48,'Status');

$prop = array('HeaderColor'=>array(255,150,100),
    'color1'=>array(210,245,255),
    'color2'=>array(255,255,210),
    'padding'=>2);
$pdf->Table($link,"select Leave_Type,LeaveSub_Type,Start,End,Remarks,Status from holiday where EMP_ID = '".$empidinfo."'",$prop);
//$pdf->Image('img/male.png',10,10,-300);
$fileName = "Leave Summary Of - ".$row['Name'].".pdf";
$pdf->Output($fileName, 'D');
}
ob_end_flush();
?>

The mysql_table.php file mysql_table.php 文件

<?php
require('fpdf.php');

class PDF_MySQL_Table extends FPDF
{
    protected $ProcessingTable=false;
    protected $aCols=array();
    protected $TableX;
    protected $HeaderColor;
    protected $RowColors;
    protected $ColorIndex;

    function Header()
    {
    // Print the table header if necessary
        if($this->ProcessingTable)
            $this->TableHeader();
    }

    function TableHeader()
    {
        $this->SetFont('Arial','B',12);
        $this->SetX($this->TableX);
        $fill=!empty($this->HeaderColor);
        if($fill)
            $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
        foreach($this->aCols as $col)
            $this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
        $this->Ln();
    }

    function Row($data)
    {
        $this->SetX($this->TableX);
        $ci=$this->ColorIndex;
        $fill=!empty($this->RowColors[$ci]);
        if($fill)
            $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
        foreach($this->aCols as $col)
            $this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
        $this->Ln();
        $this->ColorIndex=1-$ci;
    }

    function CalcWidths($width, $align)
    {
    // Compute the widths of the columns
        $TableWidth=0;
        foreach($this->aCols as $i=>$col)
        {
            $w=$col['w'];
            if($w==-1)
                $w=$width/count($this->aCols);
            elseif(substr($w,-1)=='%')
                $w=$w/100*$width;
            $this->aCols[$i]['w']=$w;
            $TableWidth+=$w;
        }
    // Compute the abscissa of the table
        if($align=='C')
            $this->TableX=max(($this->w-$TableWidth)/2,0);
        elseif($align=='R')
            $this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
        else
            $this->TableX=$this->lMargin;
    }

    function AddCol($field=-1, $width=-1, $caption='', $align='L')
    {
    // Add a column to the table
        if($field==-1)
            $field=count($this->aCols);
        $this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
    }
    function Table($link, $query, $prop=array())
        {
        // Execute query
        $res=mysqli_query($link,$query) or die('Error: '.mysqli_error($link)."<br>Query: $query");
        // Add all columns if none was specified
        if(count($this->aCols)==0)
        {
            $nb=mysqli_num_fields($res);
            for($i=0;$i<$nb;$i++)
                $this->AddCol();
        }
        // Retrieve column names when not specified
        foreach($this->aCols as $i=>$col)
        {
            if($col['c']=='')
            {
                if(is_string($col['f']))
                    $this->aCols[$i]['c']=ucfirst($col['f']);
                else
                    $this->aCols[$i]['c']=ucfirst(mysqli_fetch_field_direct($res,$col['f'])->name);
            }
        }
        // Handle properties
        if(!isset($prop['width']))
            $prop['width']=0;
        if($prop['width']==0)
            $prop['width']=$this->w-$this->lMargin-$this->rMargin;
        if(!isset($prop['align']))
            $prop['align']='C';
        if(!isset($prop['padding']))
            $prop['padding']=$this->cMargin;
        $cMargin=$this->cMargin;
        $this->cMargin=$prop['padding'];
        if(!isset($prop['HeaderColor']))
            $prop['HeaderColor']=array();
        $this->HeaderColor=$prop['HeaderColor'];
        if(!isset($prop['color1']))
            $prop['color1']=array();
        if(!isset($prop['color2']))
            $prop['color2']=array();
        $this->RowColors=array($prop['color1'],$prop['color2']);
        // Compute column widths
        $this->CalcWidths($prop['width'],$prop['align']);
        // Print header
        $this->TableHeader();
        // Print rows
        $this->SetFont('Arial','',11);
        $this->ColorIndex=0;
        $this->ProcessingTable=true;
        while($row=mysqli_fetch_array($res))
            $this->Row($row);
        $this->ProcessingTable=false;
        $this->cMargin=$cMargin;
        $this->aCols=array();
    }
    }
    ?>

As far as I have checked I have not left any whitespaces or word spaces and also have tried setting the following据我检查,我没有留下任何空格或单词空格,并且还尝试设置以下内容

ob_clean();
ob_end_flush(); 
ini_set("session.auto_start", 0);

Error Image错误图像

错误描述

The files also doesn't contain BOM characters这些文件也不包含BOM字符

BOM 字符检查

I shifted the whole fpdf code to the top of the php document and now it is getting downloaded.我将整个 fpdf 代码移到 php 文档的顶部,现在正在下载它。 No changes to the code were done未对代码进行任何更改

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用FPDF致命错误:有些数据已经输出,无法发送PDF文件? - Fatal error using FPDF:Some data has already been output, can't send PDF file? FPDF 错误:部分数据已经输出。 无法发送 PDF 文件 - FPDF error: some data has already been output. Can't send PDF file FPDF错误:已经输出了一些数据,无法发送PDF文件 - FPDF error: Some data has already been output, can't send PDF file magento FPDF错误:已经输出了一些数据,无法发送PDF文件 - magento FPDF error: Some data has already been output, can't send PDF file FPDF错误:有些数据已经输出,无法在000webhost上发送PDF文件 - FPDF error: Some data has already been output, can't send PDF file on 000webhost FPDF错误:已经输出了一些数据,无法发送PDF文件(输出从C:\\ xampp \\ htdocs \\ movie \\ form.php:15开始) - FPDF error: Some data has already been output, can't send PDF file (output started at C:\xampp\htdocs\movie\form.php:15) FPDF 错误:一些数据已经输出,无法发送 PDF - FPDF error: Some data has already been output, can't send PDF FPDF 错误:部分数据已输出,无法发送 PDF 文件。 尝试了一切,但没有任何帮助 - FPDF Error: Some data has already been output, can't send PDF file. Tried everything but nothing helped mPDF错误:部分数据已经输出到浏览器,无法发送PDF文件 - mPDF error: Some data has already been output to browser, can't send PDF file TCPDF ERROR:部分数据已经输出,无法发送PDF文件 - TCPDF ERROR: Some data has already been output, can't send PDF file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM