gpt4 book ai didi

php - 无法使用Yii写入mPDF临时文件

转载 作者:行者123 更新时间:2023-12-04 13:37:40 30 4
gpt4 key购买 nike

我试图以PDF格式打印证书,但是当我将代码推送到暂存时,它说

Temporary files directory "/var/www/protected/vendor/mpdf/mpdf/src/Config/../../tmp" is not writable

我不确定如何更改权限以及如何更改自定义目录。

这是我单击以获得证书的按钮的代码:
 <a class="btn btn-sd btn-sd-ghost btn-sd-ghost-black margin-right-lg" href="<?php echo $this->createUrl('//idea/frontend/pdf', array('id'=>$model->id))?>" target="_blank">Get Your Certificate<i class="icon-right-small"></i></a> 
<?php endif; ?>

这是 Controller :
public function actionPdf($id){
$model = HUB::getOrganization($id);
$orgtitle = $model->title;

$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4-L']);
$mpdf->WriteHTML("<html><body style='background-image:url(\"/images/cert-idea.jpg\"); background-image-resize: 5; background-position: top center;'></body></html>");

$mpdf->WriteHTML("<div style='text-align:center; display:table; height:100%; width:100%; padding-top:28%;'><h1 style='display:table-cell; vertical-align:middle; font-size:40px;'>".$orgtitle."</h1></div>");


$mpdf->Output('IDEA-CERT-'.$orgtitle.'.pdf', 'I');
}

希望有人可以帮助我解决这个问题。谢谢!

最佳答案

尝试按照the documentation中所述的自定义临时目录:

It is recommended to set custom temporary directory via tempDir configuration key. The directory must have write permissions (mode 775 is recommended).


<?php
$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);

您将对Composer vendor-dir之外的目录的权限拥有更多控制权。

如果Web服务器用户(通常为 www-data)必须访问目录,则模式775可能不够。如有必要,请使用777。

请注意,mPDF会自动清除其临时目录,因此请使用仅专用于mPDF的目录。

关于php - 无法使用Yii写入mPDF临时文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48554488/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com