2013-01-07 147 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