Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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; ?>

and this is the controller:

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Try a custom temporary directory as stated in 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 MpdfMpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);

You will have far more control over permissions of a directory outside composer vendor-dir.

Mode 775 may not be sufficient if a web-server user, typically www-data has to access the directory. Use 777 if necessary.

Be warned that mPDF auto-cleans its temporary directory, so use one dedicated only to mPDF.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...