Search code examples
phpservermpdf

why Mpdf doesn't work and no errors returned


I've been using mpdf for a while, but now I'm facing a problem when I call the mpdf class, there is no error message and it doesn't work precisely on one of my servers. I've tested on other servers and it works fine. Your suggestions are welcome. Thank you. i have installed php v7.4.4 and mpdf v8. mpdf is installed with composer.

here is my php code.

require_once __DIR__ . '/vendor/autoload.php';
class Secure_pdf {
function __construct() {
    $this->create('<h1>Hello</h1>', 'output', 'azerty90');
}

function create( $html, $filename, $password, $output='I', $path='' ){

    if (! is_string($html) || ! is_string($filename) || ! is_string($password) ) {
        # code...
        return false;
    }

    if (strlen($password)<3) {
        # code...
        return false;
    }
    $mpdf = new \Mpdf\Mpdf();
    $mpdf->SetProtection(array(), $password, $password);
    $mpdf->WriteHTML($html);
    $mpdf->Output( $path . $filename .'.pdf', $output );

    return true;

   }

}

new Secure_pdf();

I try to get error with error_reporting(E_ALL) and i have
Fatal error: Uncaught Mpdf\MpdfException: Temporary files directory "/var/www/html/ptpt/temp/" is not writable
I change a temp folder and define temp folder permission to 775 and change folder user to www-data but the error message hasn't gone away.


Solution

  • I found a solution. I integrated mpdf in wordpress and i change a temp directory to wordpress uploads directory and it work.