mPDF 传递 URL 参数以创建 PDF 文件

mPDF pass URL with parameters to create a PDF file

我创建了一个pdf.php

<?php 
include("mpdf60/mpdf.php");

$url = $_GET['url'];

ob_start(); 
include($url);
$html = ob_get_clean();
$mpdf=new mPDF('utf-8', 'A3-L'); 
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>

但是当传递参数例如:

<?php

$url = 'gerencial_consad.php?mes='.$mes.'&ano='.$ano.'&menu=N';

?>

<a href="pdf.php?url=<?php echo $url; ?>">[ Gerar PDF ]</a>

创建文件 PDF 时出现错误:

警告:包括(gerencial_consad.php?mes=01):无法打开流:第 7 行 C:\wamp64\www\codforv2\pdf.php 中的结果太大 调用堆栈

时间记忆功能位置

1 0.0005 240264 {main}( ) ...\pdf.php: ( !) 警告:include():在 C:\wamp64\www\codforv2\pdf.[=54= 中打开 'gerencial_consad.php?mes=01' 以包含 (include_path='.;C:\php\pear') 失败] 第 7 行 调用堆栈

时间记忆功能位置

1 0.0005 240264 {main}( ) ...\pdf.php:

请帮帮我!!!

谢谢!

您不想包含 URL,您想使用 HTTP 客户端下载 URL 的内容。

最简单的方法,可能受限于 allow_url_fopen ini 设置,是使用 file_get_contents 函数。

您需要将整个 URL 传递给函数:

$url = $_GET['url']; // http://example.com/
$html = file_get_contents($url);
$mpdf->WriteHTML($html);

警告:通过使用未经过滤和未经处理的用户输入(直接$_GET['url']),您将在您的应用程序中打开一个安全漏洞。始终将输入限制为您认为安全的内容。

您最好只从请求中获取 URL 的参数,并在内部组合最终的 URL。