无法使用Yii写入mPDF临时文件 [英] mPDF temporary file is not writable using Yii

查看:49
本文介绍了无法使用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 \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');
    }

希望有人可以帮助解决我的问题.谢谢!

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 \Mpdf\Mpdf(['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可能不足.如有必要,请使用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.

这篇关于无法使用Yii写入mPDF临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆