How To Generate a QR Code using Codeigniter

Hello, Welcome back to KDJ Guru official blog. From this post, you will learn how to generate a QR code using the Codeigniter framework. As a modern framework, it is very flexible and easy to learn. But, most of the times, you have to write most of the functions from scratch by spending more time. Anyways, you can use some useful libraries to save time. This is not a library. But if you need to use this code snippet, you must have knowledge of Views and  Controllers. OK, let’s roll.

View (qrcode.php)

[code]<!DOCTYPE html>
<h1>How to generate QR Code using Codeigniter</h1>
<form action=”<?php echo base_url();?>QrController/qrcodeGenerator” method=”post”>
<input type=”text” name=”qrcode_text”>


Controller (QrController.php)

defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);
class Welcome extends CI_Controller
function __construct ()
public function index()
public function qrcodeGenerator ( )
$qrtext = $this->input->post(‘qrcode_text’);
//file path for store images
$SERVERFILEPATH = $_SERVER[‘DOCUMENT_ROOT’].’/qrcodeci/images/’;
$text = $qrtext;
$text1= substr($text, 0,9);
$file_name1 = $text1.”-Qrcode” . rand(2,200) . “.png”;
$file_name = $folder.$file_name1;
echo”<center><img src=”.base_url().’images/’.$file_name1.”></center”;
echo ‘No Text Entered’;

I hope, you could do it and make it work by yourself. If you have any issue with this code snippet, please send me a message or leave a comment. Thank You for being with us. Have a nice day!