2015-04-16 55 views
0

我想輸出PDF文件,稍後,我希望他們被donwloaded,沒有顯示。 但現在,我遇到了問題。我創建一個WordPress插件,但我得到這個錯誤:FPDF錯誤在wordpress

FPDF error: Some data has already been output, can't send PDF file (output started at C:\xampp\htdocs\wp-admin\menu-header.php:132)

這是代碼我目前有:

<?php 
/** 
* Plugin Name: PHPtoPDFTest 
* Plugin URI: http://mypluginuri.com/ 
* Description: Turns PHP into a PDF 
* Version: 1.0 or whatever version of the plugin (pretty self explanatory) 
* Author: Brent Lobbezoo 
* Author URI: Author's website 
* License: A "Slug" license name e.g. GPL12 
*/ 
add_action('admin_menu', 'PHPtoPDFTest_admin_actions'); 
function PHPtoPDFTest_admin_actions() { 
    add_options_page('PHPtoPDFTest', 'PHPtoPDFTest', 'manage_options', __FILE__, 'PHPtoPDFTest_admin'); 
} 

function PHPtoPDFTest_admin() { 
    //Hier worden de database inloggegevens opgeslagen 
    $username = "root"; 
    $password = ""; 
    $hostname = "localhost"; 

    //Hier wordt connectie gemaakt met mysql 
    $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); 
    echo "Connected to MySQL<br>"; 

    //Hier wordt de database Test gekozen, waarin alles op dit moment staat opgeslagen 
    $selected = mysql_select_db("test",$dbhandle) or die("Could not select examples"); 

    //Het result, een array, van de query wordt hier in $result gestopt 
    $result = mysql_query(
     " 
     SELECT lid.Lid_ID, lid.Naam, lid.Adres, lid.Email, 
     (SELECT Bedrag FROM Tarief WHERE Soort = 'contributie' LIMIT 1) AS 'Contributie', 
     (SELECT Bedrag FROM Tarief WHERE Soort = 'liggeld' LIMIT 1)*IFNULL(schip.lengte,0) AS 'Liggeld', 
     (SELECT Bedrag FROM Tarief WHERE Soort = 'contributie' LIMIT 1)+ 
     (SELECT Bedrag FROM Tarief WHERE Soort = 'liggeld' LIMIT 1)*IFNULL(schip.lengte,0) AS 'Totaal' 
     FROM lid 
     LEFT JOIN Schip ON lid.Schip=schip.Naam 
     WHERE lid.ContributieBetaald <> 'ja' 
     " 
     ); 

    ob_start(); 
    require('fpdf.php'); 

    while ($row = mysql_fetch_assoc($result)) { 
     $pdf = new FPDF(); 
     $pdf->AddPage(); 
     $pdf->SetFont('Arial','B',16); 
     $pdf->Cell(40,10,$row{'Naam'},1); 
     $pdf->Cell(40,10,$row{'Adres'},1); 
     $pdf->Cell(40,10,$row{'Email'},1); 
     $pdf->Cell(40,10,'Contributie bedrag: '.$row{'Contributie'},1); 
     $pdf->Cell(40,10,'Liggeld Bedrag: '.$row{'Liggeld'},1); 
     $pdf->Cell(40,10,'Totaal bedrag: '.$row{'Totaal'},1); 
     $pdf->Output(); 
    } 
} 
?> 

基本上,我需要生成一個收據中的每個用戶數據庫(目前只有兩個),但由於某種原因,彈出錯誤!

這是行132 mneu頭代碼:

echo "\n\t<a href='{$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>$title</div></a>"; 

如果有人知道如何解決這個問題,我會非常心存感激!

回答

1

如果您以前已經將文本輸出到屏幕,則FPDF無法輸出到瀏覽器。看起來頭像是從你所顯示的內容引起這個問題。您應該打開一個空白頁面或窗口,其中一個不會擴展或調用WP的模板,並在那裏生成PDF。