在用户填写表格(开具发票)后,我开始使用库(Mpdf)制作PDF。这是第一次,所以我整天都在尝试解决此问题,我放弃了。
问题是,当我添加require时,php可以正常运行,但是当我添加$mpdf = new \Mpdf\Mpdf ([])
时,它将失败。在浏览器中,我得到了这个错误:
致命错误:未捕获Mpdf \ Mpdf异常:临时文件目录“ /opt/lampp/htdocs/invoice/vendor/mpdf/mpdf/src/Config/../../tmp”不可写在/ opt / lampp中/htdocs/invoice/vendor/mpdf/mpdf/src/Cache.php:17堆栈跟踪:#0 /opt/lampp/htdocs/invoice/vendor/mpdf/mpdf/src/ServiceFactory.php(59):Mpdf \ Cache -> __ construct('/ opt / lampp / htdo ...')#1 /opt/lampp/htdocs/invoice/vendor/mpdf/mpdf/src/Mpdf.php(1033):
Mpdf \ ServiceFactory-> getServices(Object(Mpdf \ Mpdf),Object(Psr \ Log \ NullLogger),数组,0,Object(Mpdf \ Language \ LanguageToFont),Object(Mpdf \ Language \ ScriptToLanguage),NULL, NULL,NULL,NULL)#2 /opt/lampp/htdocs/invoice/novillo.php(7):Mpdf \ Mpdf-> __ construct(Array)#3 {main}抛出/ opt / lampp / htdocs / invoice / vendor /mpdf/mpdf/src/Cache.php,第17行
我真的不知道如何解决它。我正在尝试使用mpdf制作pdf
<?php
require_once('vendor/autoload.php');
$mpdf = new \Mpdf\Mpdf ([]);
致命错误:未捕获Mpdf \ Mpdf异常:临时文件目录“ /opt/lampp/htdocs/invoice/vendor/mpdf/mpdf/src/Config/../../tmp”不可写在/ opt / lampp中/htdocs/invoice/vendor/mpdf/mpdf/src/Cache.php:17堆栈跟踪:#0 /opt/lampp/htdocs/invoice/vendor/mpdf/mpdf/src/ServiceFactory.php(59):Mpdf \ Cache -> __ construct('/ opt / lampp / htdo ...')#1 /opt/lampp/htdocs/invoice/vendor/mpdf/mpdf/src/Mpdf.php(1033):Mpdf \ ServiceFactory-> getServices(Object (Mpdf \ Mpdf),对象(Psr \ Log \ NullLogger),数组,0,对象(Mpdf \ Language \ LanguageToFont),对象(Mpdf \ Language \ ScriptToLanguage),NULL,NULL,NULL,NULL,NULL)#2 / opt / lampp / htdocs / invoice / novillo.php(7):Mpdf \ Mpdf-> __ construct(Array)#3 {main}放在/opt/lampp/htdocs/invoice/vendor/mpdf/mpdf/src/Cache.php中第17行
答案 0 :(得分:0)
您需要一个用于存放临时文件的文件夹,并且必须在构造函数上指明路由:
$mpdf = new \Mpdf\Mpdf(['tempDir' => '../../../temp']);
确保该文件夹具有写和读权限,并将其添加到php文档的标头中还表示:
use \Mpdf\Mpdf;