2013-01-07 146 views
-2

您好,我需要創建一個pdf下載線smarty我已經從fpdf,在火蟲顯示PDF文件,但我可以創建一個下載鏈接爲smarty我的代碼如下。如何下載pdf時創建smarty從pdf創建的pdf

$content = $this->view->fetch($pdf->Output()); 
$router->disableRender(); 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/pdf'); 
    header('Content-disposition: attachment; filename="doc.pdf"'); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 

    ob_clean(); 
    flush(); 

    readfile(doc.pdf); 
    die; 

請幫我thax進階........

回答

0

在你的代碼的頂部,你說

$content = $this->view->fetch($pdf->Output()); 
$router->disableRender(); 
底部

那麼,你說

ob_clean(); 
flush(); 

readfile(doc.pdf); 
die; 

現在,除了事實上,這應該是一個PHP警告 - 未定義常量doc.pdf,假設一個字符串等 - 此代碼不會你認爲它的確如此。您從未將PDF內容寫入磁盤,因此您如何期望從磁盤讀取該內容?

您需要在發佈之前將$content寫入文件,或者您只需要echo $content

您是否甚至請嘗試排除故障?

+0

'echo $ content.'什麼都沒有發生只顯示在螢火蟲輸出'致命錯誤:在/ var/user/mohan/site/smarty_internal_template中的消息'無法解析資源名稱'''的未捕獲異常'SmartyException'。 php:941錯誤顯示...... – mohan