2013-04-13 66 views
0

我使用FPDF庫,當我嘗試做一個PDF,我發現了以下錯誤:FPDF庫錯誤

Warning: Cannot modify header information - headers already sent by (output started at-----) FPDF error: Some data has already been output, can't send PDF file

//Send to standard output 
      if(ob_get_length()) 
       $this->Error('Some data has already been output, can\'t send PDF file'); 
      if(php_sapi_name()!='cli') 
      { 
       //We send to a browser 
       header('Content-Type: application/pdf'); 
       if(headers_sent()) 
        $this->Error('Some data has already been output, can\'t send PDF file'); 
       header('Content-Length: '.strlen($this->buffer)); 
       header('Content-Disposition: inline; filename="'.$name.'"'); 
       header('Cache-Control: private, max-age=0, must-revalidate'); 
       header('Pragma: public'); 
       ini_set('zlib.output_compression','0'); 
      } 
      echo $this->buffer; 
+0

檢查這個職位:[頭已經發送PHP](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) – SeanWM

+1

你的問題在'-----'。 – mario

回答

1

在某些時候,一些導致PHP將數據發送到客戶。

如果你看不到任何原因(即你不明確發送數據),那麼在你的PHP代碼(<?php)開始之前在源代碼中尋找雜散文本,空格,換行符等文件。

這應該解決問題。

注意:正如wh1t3h4ck5指出的那樣,如果錯誤的來源不在當前文件中,您可能還需要檢查包含的文件。尋找最近修改過的文件。

+1

+1此外,即使包含的文件可能會導致此問題,請檢查非ANSI腳本(主要是UTF包含此原因)。 – Wh1T3h4Ck5

+0

@ Wh1T3h4Ck5 +1。真正。我在答案中添加了該信息。 – Jean