-2

嗨,我需要在 smarty 中创建一个 pdf 的下载行,我是从 fpdf 制作的,在 fire bug 中显示 pdf 文件,但我可以在 smarty 中创建一个下载链接,我的代码如下。

$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 adv........

4

1 回答 1

0

在代码的顶部,你说

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

然后在底部,你说

ob_clean();
flush();

readfile(doc.pdf);
die;

现在,除了这应该会导致 PHP 警告(未定义的常量 doc.pdf、假设是字符串等)之外,这段代码并没有按照您的想法执行。您绝不会将 PDF 内容写入磁盘,那么您如何期望从磁盘读取它会起作用?

您需要$content在发出文件之前写入文件,或者只需要echo $content.

您是否尝试过对此进行故障排除?

于 2013-01-07T11:59:42.967 回答