Home > Mobile >  i'm stuck in Warning: require_once(C:\xampp\htdocs\test04/vendor/composer/autoload.php): and
i'm stuck in Warning: require_once(C:\xampp\htdocs\test04/vendor/composer/autoload.php): and

Time:11-06

I change $mpdf = new Mpdf\Mpdf(); to $mpdf = new mpdf\mpdf(); but still error i'm using mpdf/mpdf (v6.1.3)

Fatal error: Uncaught Error: Class "Mpdf\Mpdf" not found in C:\xampp\htdocs\test04\makepdf.php:11 Stack trace: #0 {main} thrown in C:\xampp\htdocs\test04\makepdf.php on line 11

<?php 
require_once __DIR__ . '/composer/autoload.php';

    $Fname = $_POST['Fname'];
      $Lname = $_POST['Lname'];
      $User = $_POST['User'];
      $City = $_POST['City'];
      $State = $_POST['State'];
      $Zip = $_POST['Zip'];

      $mpdf = new Mpdf\Mpdf();


      $data ='';

      $data ='Your Details';

      $data ='<strong>First Name</strong>' .$Fname . '<br/>';
      $data ='<strong>First Name</strong>' .$Lname . '<br/>';
      $data ='<strong>First Name</strong>' .$User . '<br/>';
      $data ='<strong>First Name</strong>' .$City . '<br/>';
      $data ='<strong>First Name</strong>' .$State . '<br/>';
      $data ='<strong>First Name</strong>' .$Zip . '<br/>';

      $mpdf->WriteHTML($data);

      $mpdf->Output('myfile.pdf', 'D');


[here's the code i copied for require_once][1]


  [1]: https://i.stack.imgur.com/B94sr.png

CodePudding user response:

If your package is located in other directory than file from you are calling it you must include full namespace.

Try changing

$mpdf = new Mpdf\Mpdf();

to

$mpdf = new \Mpdf\Mpdf();

CodePudding user response:

mPDF has not used any namespacing until v7 (released in late 2017). Older versions than that simply use

$mpdf = new Mpdf();

If you are starting a new project, please do not use v6.1.3 - that version has been released in 2016 and is horribly outdated

CodePudding user response:

You are either missing the required library or else calling it incorrectly.

Possible fixes include:

  1. Instead of:

    $mpdf = new Mpdf\Mpdf();

Use:

$mpdf = new Mpdf();
  1. Make sure that your dependencies are available and installed. Preferrably install via composer so that all dependencies are installed.
  •  Tags:  
  • php
  • Related