Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

php - Fatal error: Some data has already been output, can't send PDF file

so this is my code

 <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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What you try to use the result it's an octet stream which sends the PDF file to your Browser to download the file. In this case you can't have an output before. Create a single file and output that PDF file without writing anything before. Then you can download the file.

That is what the error message tells you. Don't output anything before the output of the PDF file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...