Generate QR Code In Codeignater
we are using the QR Code library. PHP QR Code is open source library for generating QR Code, 2-dimensional barcode.
Now create a PHP file in the same folder where you placed the phpqrcode folder. We need to include ‘qrlib.php‘ file to use a function named ‘png()‘. This function is inside the QRcode class which outputs a QR code directly in the browser when we pass some text as a parameter.
Download PHP QR Code Library – download
Syntax
QRcode::png(text, file, ecc, pixel_size, frame_size);
text – the text message which needs to be in a QR code,
file – location to save the generated QR code,
ecc – to specify the error correction capability of the QR code, it has four levels: L, M, Q and H,
pixel_size – to specify the pixel size of QR,
frame_size – to specify the size of the QR.
Using Codignater Controller
<?php
class Amd_qrganarate extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('Home_Model','H');
$this->load->library('phpqrcode/qrlib');
}
public function GenerateQrAmd()
{
$qrtext = "upi://pay?pa=8519917752@ybl&pn=AbdulMohammad&tr=GTZ272727&am=350&cu=INR&mc=5411";
print_r($qrtext);
if(isset($qrtext))
{
echo $SERVERFILEPATH = $_SERVER['DOCUMENT_ROOT'].'/assets/qr-amd/';
$text = $qrtext;
$text1= substr($text, 0,9);
$folder = $SERVERFILEPATH;
$file_name1 = "testing-Qrcode" . rand(2,400) . ".png";
$file_name = $folder.$file_name1;
QRcode::png($text,$file_name);
echo"<center><img src=".base_url().'assets/qr-amd/'.$file_name1."></center";
}
else
{
echo 'No Text Entered';
}
}
}
?>
Output
