【问题标题】:FPDF error: Some data has already been output by using FPDFFPDF 错误:使用 FPDF 已经输出了一些数据
【发布时间】:2013-09-19 11:46:30
【问题描述】:

我在尝试输出时遇到 FPDF 错误

    require('cons.php');  
    $fpd = new fpdfx();
    $fpd->AddPage();
    $fpd->SetFont('Arial','B',16);
    $fpd->Cell(40,10,'Hello World!');
    $fpd->Output();

我在 cons.php 中的代码很少

        error_reporting(E_ERROR | E_PARSE); //For Error Reporting        
        session_start();
        setlocale(LC_MONETARY, 'da_DK');
        set_time_limit(0);
        define("DBHOST","XXX");
        define("DBNAME","XXX");
        define("DBUSER","XXX");
        define("DBPASS","XXX");       
        define("TODAYSDATE",date('d-m-Y', strtotime("+4 months")));
        define("UPDATEDATE",date('d-m-Y', strtotime("+5 months")));       
        define("LanguageFilesURL",'XXX');   

        global $instance;
        require("inc/Email-class.php");
        require("inc/database_class.php");

email 类具有电子邮件功能和一些电子邮件功能

这是我的电子邮件课程详细信息

                require("fpdf/fpdf.php");
                class fpdfx extends FPDF
                {

                }


                class Email_class
                {
                }

当我试图获得一些输出时,它的节目

FPDF 错误:部分数据已输出,无法发送 PDF 文件

【问题讨论】:

    标签: php fpdf


    【解决方案1】:

    尝试注释掉 $fpd->Output();看看你是否收到任何通知或其他发送到输出的数据。

    如果没有,请深入研究 Output() 方法并使用 die();直到你找到输出一些数据的原因!

    【讨论】:

    • case 'D': // 下载文件 $this->_checkoutput(); header('Content-Type: application/x-download'); header('Content-Disposition: attachment; filename="'.$name.'"'); header('Cache-Control: private, max-age=0, must-revalidate'); header('Pragma: public');回声 $this-> 缓冲区;死();休息;像这样??
    • 你有没有试过只注释掉 $fpd->Output(); ?在 Output() 方法中,你应该死;在发送标头之前,看看是否已经输出了任何内容。
    • 是的,我都试过了,都不管用了,//下载文件 $this->_checkoutput(); //header('Content-Type: application/x-download'); //header('Content-Disposition: attachment; filename="'.$name.'"'); //header('Cache-Control: private, max-age=0, must-revalidate'); //header('Pragma: public');死(); echo $this->buffer;
    • 我从 OutPut 函数中注释所有标题
    • 奇怪,死了;应该防止回显 $this->buffer... 无论如何,您可以尝试的另一件事是从包含的文件中删除所有关闭的 PHP 标记。包含文件时,可能会有隐藏字符发送到输出。