可以';t使用php、mysql获取pdf文件作为输出


can't get pdf file as output using php,mysql

我想使用fpdf 生成PDF文件

但我犯了这样的错误:fpdf错误:一些数据已经输出无法发送pdf文件

<?php
    $indexcontent = mysql_real_escape_string($_GET['index']);
     $detailview = mysql_query("SELECT * FROM `searchengine` WHERE `indexcontent` = '$indexcontent'") or die(mysql_error());
    if($result = mysql_fetch_assoc($detailview))
    {
    $filepdf = $result['maincontent'];
    require('fpdf.php');
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'$filepdf');
    $pdf->Output();
    }
?>

不要把变量放在单引号之间,尽量放在双引号之间。

试试这个:

<?php
    $indexcontent = mysql_real_escape_string($_GET['index']);
    $detailview = mysql_query("SELECT * FROM `searchengine` WHERE `indexcontent` = '$indexcontent'") or die(mysql_error());
    require('fpdf.php');
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    if($result = mysql_fetch_assoc($detailview))
    {
    $filepdf = $result['maincontent'];
    $pdf->Cell(40,10,$filepdf);
    }
    $pdf->Output();
?>