How to generate Qrcode Using Codeigniter?

Today, We want to share with you qr code codeigniter.In this post we will show you codeigniter barcode, hear for membuat barcode dengan codeigniter we will give you demo and example for implement.In this post, we will learn about PHP Barcode Generator Tutorial with an example.

Today Tutorial about is how to generate qrcode using Codeigniter. So firstly we know about what is the QR Code.

What is Qr Code ?

QR stands for quick response it’s another form of bar code but some significant difference between them while barcodes hold full details only in the horizontal direction, QR codes stores full details in both direction horizontally as well as vertically. In QR code we can store full details like web url, email, phone number, Address or any types of the set strings etc.

Full details of Qr code is decoded using dedicated QR code scanner or Qr code decoding Application.

jQuery Ajax QR Code Generator PHP script Download
jQuery Ajax QR Code Generator PHP script Download

If you are looking for a How To Create BarCode generator using PHP then you must go through with this step by step tutorial.

So let’s starts the Codeigniter coding sections.

Library

i use PHPQRCODE library for generating the QR code.So you can download the library using this link PHP QR CODE Library Download

View

qrcodetext.php
And then i Make the view file for enter the text and generate the QR code from this text




	php qrcode generator - www.pakainfo.com


How to generate QR Code using Codeigniter - www.pakainfo.com

Some brief description of the Qrcontroller.php file

i can Load the Php QR Code library in the constructor of the controller

Qrcontroller.php

function __construct ()
{	
  parent::__construct();
  $this->load->library('phpqrcode/qrlib');
  $this->load->helper('url');
}

Next i get the entered text and generate the QR Code

public function qrcodeGenerator ( )
{
		
    $phpqrcode_data = $this->input->post('phpqrcode_input');	
    if(isset($phpqrcode_data))
    {
	
         $SERVERFILEPATH = $_SERVER['DOCUMENT_ROOT'].'/qrcode-generation-in-codeigniter/uploads/';
	 $text = $phpqrcode_data;
	 $string_qr= substr($text, 0,9);	
	 $directory = $SERVERFILEPATH;
	 $phpqrcodefilenm1 = $string_qr."-Qrcode" . rand(2,200) . ".png";
	 $phpqrcodefilenm = $directory.$phpqrcodefilenm1;
	 QRcode::png($text,$phpqrcodefilenm);		
	 echo"
qr code codeigniter
  • $phpqrcode_data – Inputted text that can be encoded in QR Code
  • $SERVERFILEPATH – Path of server where QR Images to be stored
  • $phpqrcodefilenm1 – Name of QR uploads file
  • QRcode::png($text,$phpqrcodefilenm) – Using QRcode::png() function we generate QR code it takes two parameter first one is entered text and 2nd is the name of the QR image file.

Controller

QrController.php

load->library('phpqrcode/qrlib');
		$this->load->helper('url');
	}
 
	public function index()
	{
		$this->load->view('qrcodetext.php');
	}
 
	public function qrcodeGenerator ( )
	{
		
		
		$phpqrcode_data = $this->input->post('phpqrcode_input');
		
		if(isset($phpqrcode_data))
		{
 
			//file path for store uploads
		    $SERVERFILEPATH = $_SERVER['DOCUMENT_ROOT'].'/qrcodeci/uploads/';
			$text = $phpqrcode_data;
			$string_qr= substr($text, 0,9);
			
			$directory = $SERVERFILEPATH;
			$phpqrcodefilenm1 = $string_qr."-Qrcode" . rand(2,200) . ".png";
			$phpqrcodefilenm = $directory.$phpqrcodefilenm1;
			QRcode::png($text,$phpqrcodefilenm);
			
			echo"
qr code codeigniter
Dynamic QR codes Generator in Laravel 5.7
Dynamic QR codes Generator in Laravel 5.7

You can generate QR codes using CodeIgniter by using a third-party library. Here's an example of how to do it using the phpqrcode library:

Download the phpqrcode library from https://sourceforge.net/projects/phpqrcode/.
Extract the contents of the downloaded archive to the application/third_party directory of your CodeIgniter project.
Create a helper function that loads the library and generates the QR code. Place the following code in a new file named qrcode_helper.php in the application/helpers directory:


In your controller or model, load the qrcode_helper and call the generate_qr_code() function to generate the QR code. For example:

load->helper('qrcode');
        $data = 'Hello, World!';
        $filename = 'qrcode.png';
        $size = 10;
        $level = 'L';
        generate_qr_code($data, $filename, $size, $level);
        echo 'QR code generated at ' . $filename;
    }
}

In this example, we first load the qrcode_helper using the load->helper() function. We then call the generate_qr_code() function, passing in the data to encode as the first argument, the filename to save the QR code as the second argument, and the size and error correction level as the third and fourth arguments, respectively.

After the QR code is generated, we output a message indicating the filename where the QR code was saved.

Note that this example uses the default settings for the QR code size and error correction level. You can adjust these settings as needed by changing the values passed to the generate_qr_code() function.

Leave a Comment