使用 Yii 无法写入 mPDF 临时文件
我尝试打印 PDF 格式的证书,但是当我将代码推送到暂存时,它说
I tried to print a certificate in PDF but when I push my code to staging, it said
Temporary files directory "/var/www/protected/vendor/mpdf/mpdf/src/Config/../../tmp" is not writable
我不确定如何更改权限以及如何更改自定义目录.
I'm not sure how to change the permission and how to change the custom directory.
这是我点击获取证书的按钮代码:
Here's my code of a button to click to get the certificate:
<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; ?>
这是控制器:
public function actionPdf($id){
$model = HUB::getOrganization($id);
$orgtitle = $model->title;
$mpdf = new MpdfMpdf(['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');
}
希望有人能帮助解决我的问题.谢谢!
Hope someone can help on my issue. Thank you!
推荐答案
尝试使用 文档:
建议通过tempDir
配置键设置自定义临时目录.目录必须有写权限(推荐模式775).
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 MpdfMpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);
您将对 composer vendor-dir 之外的目录的权限拥有更多的控制权.
You will have far more control over permissions of a directory outside composer vendor-dir.
模式 775 可能不够,如果网络服务器用户,通常 www-data
必须访问目录.如有必要,请使用 777.
Mode 775 may not be sufficient if a web-server user, typically www-data
has to access the directory. Use 777 if necessary.
请注意,mPDF 会自动清理其临时目录,因此请使用专用于 mPDF 的目录.
Be warned that mPDF auto-cleans its temporary directory, so use one dedicated only to mPDF.
相关文章