How to Read Barcode QR Code on the Server Side Using PHP Laravel

PHP Laravel Installation on Windows and Linux

Install PHP 7.4, Composer and Laravel.

sudo apt install php7.4
php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
  • Laravel:
composer global require laravel/installer

Steps to Implement Server Side Barcode QR Code Reading Using PHP Laravel

In the following paragraphs, we will guide you through the process of developing a PHP Laravel project that can read barcode and QR code from image files on the server side.

Step 1: Install the PHP Barcode QR Code Reader Extension

There is no pre-built binary package. To read barcode and QR code in PHP, you need to build and install the PHP extension from source code on Windows and Linux.

Step 2: Scaffold a Laravel Project

Once the extension is installed, you can start a new Laravel project.

composer create-project laravel/laravel web-barcode-qrcode-reader
php artisan --version
Laravel Framework 8.83.23

composer create-project laravel/laravel:^8.0 web-barcode-qrcode-reader

Step 3: Create a Controller

Laravel controllers handle HTTP requests. We can create a controller to handle the uploaded image files and return the barcode and QR code decoding results.

php artisan make:controller ImageUploadController

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;

class ImageUploadController extends Controller
function __construct() {

function page()
return view('barcode_qr_reader');

function upload(Request $request)
$validation = Validator::make($request->all(), [
'BarcodeQrImage' => 'required'
$image = $request->file('BarcodeQrImage');
$image->move(public_path('images'), $image->getClientOriginalName());

$resultArray = DecodeBarcodeFile(public_path('images/' . $image->getClientOriginalName()), 0x3FF | 0x2000000 | 0x4000000 | 0x8000000 | 0x10000000); // 1D, PDF417, QRCODE, DataMatrix, Aztec Code

if (is_array($resultArray)) {
$resultCount = count($resultArray);
echo "Total count: $resultCount", "\n";
if ($resultCount > 0) {
for ($i = 0; $i < $resultCount; $i++) {
$result = $resultArray[$i];
echo "Barcode format: $result[0], ";
echo "value: $result[1], ";
echo "raw: ", bin2hex($result[2]), "\n";
echo "Localization : ", $result[3], "\n";
else {
echo 'No barcode found.', "\n";

return response()->json([
'message' => 'Successfully uploaded the image.'
return response()->json([
'message' => $validation->errors()->all()

Step 4: Create a Web View

Create a barcode_qr_reader.blade.php file in the public/resources/views directory. The file contains the HTML5 code for uploading an image via a form.

<!DOCTYPE html>

<title>PHP Laravel Barcode QR Reader</title>
<meta name="_token" content="" />

<H1>PHP Laravel Barcode QR Reader</H1>
<form action="" method="post" enctype="multipart/form-data">
Select barcode image:
<input type="file" name="BarcodeQrImage" id="BarcodeQrImage" accept="image/*"><br>
<input type="submit" value="Read Barcode" name="submit">
<img id="image" />
var input = document.querySelector('input[type=file]');
input.onchange = function() {
var file = input.files[0];
var fileReader = new FileReader();
fileReader.onload = function(e) {
let image = document.getElementById('image');
image.src =;

<form action="" method="post" enctype="multipart/form-data">
Route::get('/barcode_qr_reader', 'App\Http\Controllers\ImageUploadController@page');
Route::post('/barcode_qr_reader/upload', 'App\Http\Controllers\ImageUploadController@upload')->name('image.upload');

Step 5: Run the PHP Laravel Barcode QR Code Reader

Now you can run the PHP Laravel project and visit in your browser.

Source Code



Manager of Dynamsoft Open Source Projects | Tech Lover

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xiao Ling

Xiao Ling

Manager of Dynamsoft Open Source Projects | Tech Lover