问题描述
我正在编写一个wordpress插件,并创建一个生成发票并通过电子邮件发送发票的功能。 生成PDF文件时出现问题。每次尝试生成PDF文件都会以以下错误结尾:检测到错误。 PDF生成已中止:“ allow_url_include”指令已弃用
我的代码:
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\Fontvariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
try {
$mpdf = new \Mpdf\Mpdf([
'fontDir' => array_merge($fontDirs,[
__DIR__ . '/mpdf2/vendor/mpdf/mpdf/ttfonts',]),'fontdata' => $fontData + [
'roboto' => [
'R' => 'Roboto-Regular.ttf','B' => 'Roboto-Bold.ttf',]
],'mode' => 'UTF-8','format' => 'A4','default_font_size' => '12','default_font' => 'roboto','margin_left' => 25,'margin_top' => 25,'margin_right' => 25,'margin_bottom' => 25,'debug' => true,]);
$dir = plugin_dir_path(__DIR__);
$mpdf->SetdisplayMode('fullwidth');
$mpdf->WriteHTML($html);
$mpdf->Output($dir . 'haccp/invoice_pdf/' . $invoice_name,'F');
} catch (\Mpdf\MpdfException $e) { // Note: safer fully qualified exception name used for catch
// Process the exception,log,print etc.
echo $e->getMessage();
}
解决方法
mPDF捕获到由升级到PHP 7.4后设置allow_url_include
INI变量引起的错误-在ini_set
调用中或在PHP配置中(php.ini文件,.htaccess,服务器配置)
将allow_url_include
设置更改或回滚到PHP 7.3,或者禁用不推荐使用的警告。
请参见https://www.php.net/manual/en/filesystem.configuration.php