Home » Php » php – Warning: file_get_contents(test.png): failed to open stream: No such file or directory in

php – Warning: file_get_contents(test.png): failed to open stream: No such file or directory in

Posted by: admin February 25, 2020 Leave a comment

Questions:

i am trying to generate a qrcode using mpdf . but I can’t succeed in any way.I first create a qrcode using jquery but it does not allow mpdf ..
Later I try to create a qrcode using the QR code generating library but no
I can’t succeed.

my first try code

use Mpdf\QrCode\QrCode;
use Mpdf\QrCode\Output;

$qrCode = new QrCode('Lorem ipsum sit dolor');

$output = new Output\Png();

// Save black on white PNG image 100px wide to filename.png
$output->output($qrCode, 100, [255, 255, 255], [0, 0, 0], 'filename.png');

error

Fatal error: Uncaught Error: Class 'Mpdf\QrCode\QrCode' not found in E:\Xampp\htdocs\lab_allwork\certificate\certificate1\certificate.php:8 Stack trace: #0 {main} thrown in E:\Xampp\htdocs\lab_allwork\certificate\certificate1\certificate.php on line 8

my second try code

use Zxing\QrReader;
require __DIR__ . "/vendor/autoload.php";
$qrcode = new QrReader('test.png');
$text = $qrcode->text();
print($text);

error

Warning: file_get_contents(test.png): failed to open stream: No such file or directory in E:\Xampp\htdocs\mpdfqrcode\vendor\khanamiryan\qrcode-detector-decoder\lib\QrReader.php on line 34
Warning: imagecreatefromstring(): Empty string or invalid image in E:\Xampp\htdocs\mpdfqrcode\vendor\khanamiryan\qrcode-detector-decoder\lib\QrReader.php on line 35
Fatal error: Uncaught InvalidArgumentException: Invalid image source. in E:\Xampp\htdocs\mpdfqrcode\vendor\khanamiryan\qrcode-detector-decoder\lib\QrReader.php:66 Stack trace: #0 E:\Xampp\htdocs\mpdfqrcode\qrcode.php(4): Zxing\QrReader->__construct(‘test.png’) #1 {main} thrown in E:\Xampp\htdocs\mpdfqrcode\vendor\khanamiryan\qrcode-detector-decoder\lib\QrReader.php on line 66

my third try code

namespace Mpdf\QrCode\Output;

use Mpdf\QrCode\QrCode;

/**
 * @group unit
 */
class HtmlTest extends \PHPUnit\Framework\TestCase
{

    public function testOutput()
    {
        $code = new QrCode('LOREM IPSUM 2019');

        $output = new Html();

        $data = $output->output($code);

        $filename = __DIR__ . '/../../reference/LOREM-IPSUM-2019-L.html';
        file_put_contents($filename, $data);
        $this->assertSame($data, file_get_contents($filename));

        $code->disableBorder();

        $data = $output->output($code);

        $filename = __DIR__ . '/../../reference/LOREM-IPSUM-2019-L-noborder.html';
        file_put_contents($filename, $data);
        $this->assertSame($data, file_get_contents($filename));

        $code = new QrCode('LOREM IPSUM 2019', QrCode::ERROR_CORRECTION_QUARTILE);

        $data = $output->output($code);

        $filename = __DIR__ . '/../../reference/LOREM-IPSUM-2019-Q.html';
        file_put_contents($filename, $data);
        $this->assertSame($data, file_get_contents($filename));
    }
}

If anyone is successful in creating qrcode code in mpdf properly or if
you know the correct solution then please tell.

How to&Answers: