Generating QR Code Using PHP

edited May 2023 in PHP

A good open-source library for QR code generation in PHP is available in sourceforge.

  • It just needs to be downloaded and copied into the project folder.
  • This includes a module named “phpqrcode” in which there is a file named “qrlib.php”.
  • This file must be included in the code to use a function named ‘png()’, which is inside the QRcode class. png() function outputs directly a QR code in the browser when we pass some text as a parameter, but we can also create a file and store it.

Code:

<?php

// Include the qrlib file

 include 'phpqrcode/qrlib.php';

   $data["data"]["asset_number"]=$asset_number;

    $data["type"]="asset_data";

    $path = 'temp_upload/asset_qrcodes/';

    $file = $path.uniqid().".png";

    // Generates QR Code and Stores it in the directory given

    QRcode::png(json_encode($data), $file,QR_ECLEVEL_L,10,0);

    // Displaying the stored QR code from the directory

    echo "<center><img src='https://erp.gengroup.in/$file'></center>";

    echo "</br>";  

    echo "<center><h2>$asset_number</h2></center>";

Sign In or Register to comment.