严重错误:已经输出了一些数据,无法发送PDF文件 [英] Fatal error: Some data has already been output, can't send PDF file

查看:104
本文介绍了严重错误:已经输出了一些数据,无法发送PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

 <body>
  <section id="container" >
     <?php require 'inc/header.php';?>

    <section id="main-content">
      <section class="wrapper">
            <div class="row">
              <div class="row mt">
                <div class="col-md-12">
                  <div class="content-panel">
        <!-- 1ere ETAPE -->                 
                  <h1 style="text-align:center ;"> Rénitialisation  </h1>
                    <div class="etape1">
<?php 
require('inc/reni/fpdf.php'); 
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('times','B',10);
$pdf->Cell(25,7,"nom");
$pdf->Cell(30,7,"prenom");
$pdf->Ln();
$pdf->Cell(450,7,"----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
$pdf->Ln();

        include ('inc/reni/db.php');
       $sql="SELECT * FROM table1";
        $result = $bdd->query($sql);

        while($rows=$result->fetch())
        {
            $nom = $rows[0];
            $prenom = $rows[1];
            $pdf->Cell(25,7,$nom);
            $pdf->Cell(30,7,$prenom);

        
            $pdf->Ln(); 
        }

$pdf->Output();?>
                    </div>

              
                  </div>
                </div>
              </div><!-- /col-md-12 -->
            </div><!-- /row -->
      </section><! --/wrapper -->
    </section><!-- /MAIN CONTENT -->
  </section>
<?php require 'inc/script.php';?>

  </body>

错误是:致命错误:未捕获异常:FPDF错误:已经输出了某些数据,无法发送PDF文件. 我尝试一切,如添加ob_end_clean(); ob_start(); ob_end_flush(); 当我这样做时,我的页面为空,Pdf不显示

The error is : Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file. i try everything like add ob_end_clean(); ob_start ();ob_end_flush(); and when i do this my page is empty the Pdf does not display

推荐答案

您已经在输出内容.

通常在某处有回声,或者您有这样的php代码:

Usually there's an echo somewhere, or you have php code like this:

<HTML>
<?php // do my pdf thing ?>

如果pdf输出之前有任何内容,无论是空格,一些html,回显,还是打印,都会出现此错误.

If anything is in front of your pdf output, wether it be a space, some html, an echo, a print, you will get this error.

包含的pdf的php结束标记后甚至空格都可能导致此问题.

Even a space after a php closing tag of a pdf that was included can cause this.

<?php 
    class PDFWriter() {
    // some code
    }
?> <-- space here

<?php include('pdfwriter.php');

这就是为什么您应该省略纯php文件上的结束标记,以免发生这种情况的原因.

That's why you should omit the closing tags on pure php files so that doesn't happen.

在您的情况下,您要添加所有这些div

In your case you're adding all these divs

<body>
  <section id="container" >
     <?php require 'inc/header.php';?>

    <section id="main-content">
      <section class="wrapper">
            <div class="row">
              <div class="row mt">
                <div class="col-md-12">
                  <div class="content-panel">
        <!-- 1ere ETAPE -->                 
                  <h1 style="text-align:center ;"> Rénitialisation  </h1>
                    <div class="etape1">

这违反了无输出发送要求.

And that violates the no output sending requirement.

这篇关于严重错误:已经输出了一些数据,无法发送PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆