HTML2PDF 发送错误 6 "Can't load picture" 即使图片存在
HTML2PDF sends error 6 "Can't load picture" even though picture exists
我使用 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 行,但这并不是我真正需要的。
奇怪的是文件存在,你可以在浏览器中查看。
Whosebug 上的其他主题无法帮助我,因为问题略有不同。
可能会发生什么以及如何将图片强制放入我的文件中?如果您需要更多信息,请告诉我。
编辑:这是图片的日志错误
[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"]
我通过使用相对路径而不是绝对路径找到了解决方案。
感谢@CBroe 引导我找到指出用户代理问题的日志。
我使用 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 行,但这并不是我真正需要的。 奇怪的是文件存在,你可以在浏览器中查看。
Whosebug 上的其他主题无法帮助我,因为问题略有不同。
可能会发生什么以及如何将图片强制放入我的文件中?如果您需要更多信息,请告诉我。
编辑:这是图片的日志错误
[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"]
我通过使用相对路径而不是绝对路径找到了解决方案。 感谢@CBroe 引导我找到指出用户代理问题的日志。