问题描述
我使用 HTML2PDF 有一段时间了,最近,我的脚本无法加载文件中的唯一图片。
// Génération du PDF
ob_start();
echo '<page>';
echo '<br/><br/><img src="https://www.yelofox.fr/images/yelofox.jpg" style="width:200px; float:left; margin-right:20px;" />';
// MORE HTML CODE WITHOUT ERROR
echo '</page>';
$content = ob_get_clean();
require('html2pdf/html2pdf.class.php');
try
{
$pdf = new HTML2PDF('P','A4','fr');
$pdf->writeHTML($content);
ob_end_clean();
$pdf->Output('/home/yatacrea/www/images/upload/' . $data["id_client"] . '/factures/' . $fichier.'.pdf','F');
}
catch(HTML2PDF_exception $e) {
die($e);
}
脚本工作正常,除了这个错误(法语):
ERREUR n°6
Fichier : /home/yatacrea/www/scripts/html2pdf/html2pdf.class.php
Ligne : 1319
Impossible de charger l'image https://www.yelofox.fr/images/yelofox.jpg
html2pdf.class.php 中的第 1319 行就是这个(我从未编辑过这个文件):
// if the image does not exist,or can not be loaded
if (count($infos)<2) {
// if the test is activ => exception
if ($this->_testIsImage) {
throw new HTML2PDF_exception(6,$src);
}
// else,display a gray rectangle
$src = null;
$infos = array(16,16);
}
我可以使用 $pdf->setTestIsImage(false) 忽略这个错误; (这只是用彩色 div 替换图片)或删除 IMG 行,但这并不是我真正需要的。 奇怪的是文件存在,因为你可以在浏览器中查看。
StackOverFlow 上的其他 subjetcs 无法帮助我,因为问题略有不同。
会发生什么以及如何将图片强制放入我的文件中?如果您需要更多信息,请告诉我。
编辑:这是图片的日志错误
[Mon Feb 15 13:14:57 2021] [error] [client 51.68.11.227] ModSecurity: Access denied with code 403 (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file "/usr/local/apache2/conf/modsecurity/base_rules/modsecurity_crs_21_protocol_anomalies.conf"] [line "65"] [id "960009"] [rev "2.1.1"] [msg "Request Missing a User Agent Header"] [severity "NOTICE"] [tag "PROTOCOL_VIOLATION/MISSING_HEADER_UA"] [tag "WASCTC/WASC-21"] [tag "OWASP_TOP_10/A7"] [tag "PCI/6.5.10"] [hostname "www.yelofox.fr"] [uri "/images/yelofox.jpg"] [unique_id "YCplweC3lcgrp0C9HNJpBQAAADM"]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)