php - mPDF 传递带有参数的 URL 以创建 PDF 文件
问题描述
我创建了一个 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 时出现错误:
警告:include(gerencial_consad.php?mes=01):未能打开流:结果在 C:\wamp64\www\codforv2\pdf.php 中的第 7 行调用堆栈中太大
时间记忆功能位置
1 0.0005 240264 {main}( ) ...\pdf.php: ( ! ) 警告:include(): 未能打开 'gerencial_consad.php?mes=01' 以包含 (include_path='.;C:\php\pear ') 在 C:\wamp64\www\codforv2\pdf.php 第 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。
推荐阅读
- r-markdown - 新的 Pandoc distrib = 松散的交叉引用 (RMarkdown - knitr - Bookdown - thesisdown - R)
- javascript - NestJS 环境变量未定义
- php - mod_rewrite 复制 html 元素因此破坏了页面
- vim - Vim 选择光标下的整个带符号的数字(“iw”代表数字)
- reactjs - React HoC - 道具不会传递给包装的组件
- xamarin - Xamarin 表单触摸操作 HitTest 总是返回 fasle
- ruby-on-rails - 如何在 RTL YAML 文件中为 Ruby on Rails 传递变量
- php - PHP - 只允许购物车中的一个产品类别?
- pandas - Groupby依靠熊猫中的唯一日期时间
- python - 如何在numpy中通过quasi-mont carlo(QCM)技术生成高维高斯向量