- How to Read Barcode QR Code on the Server Side Using PHP Laravel
- PHP Laravel Installation on Windows and Linux
- Steps to Implement Server Side Barcode QR Code Reading Using PHP Laravel
- Step 1: Install the PHP Barcode QR Code Reader Extension
- Step 2: Scaffold a Laravel Project
- Step 3: Create a Controller
- Step 4: Create a Web View
- Step 5: Run the PHP Laravel Barcode QR Code Reader
- PHP Barcode Generator and Reader API — Generate and Scan Barcodes in PHP
- PHP Barcode Generator and Reader — Installation and Usage#
- Generate Barcodes using PHP Barcode Generator#
- Output#
- Generate 2D Barcodes using PHP Barcode Generator#
- Output#
- Generate Barcodes with a Customized Appearance in PHP#
- Output#
- Generate Barcode with Caption in PHP#
- Output#
- Read a Barcode using PHP Barcode Reader#
- Read Barcode with a Particular Symbology using PHP Barcode Reader#
- Advanced Features of PHP Barcode Generator and Reader API#
- See Also#
- Saved searches
- Use saved searches to filter your results more quickly
- License
- milind001/barcode
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
How to Read Barcode QR Code on the Server Side Using PHP Laravel
If you want to use PHP Laravel framework to build a web barcode and QR code reader, you can implement the code logic either on the client side or on the server side. Dynamsoft provides a variety of SDKs for different platforms: desktop, mobile and web. In this article, we focus on how to leverage the PHP extension built with Dynamsoft C++ Barcode SDK to read barcode and QR code on the server side. If web client side programming is your type, please refer to https://www.dynamsoft.com/barcode-reader/sdk-javascript/.
PHP Laravel Installation on Windows and Linux
php -r "copy('https://getcomposer.org/installer', '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
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
The above command installs the latest stable version of Laravel. To avoid the compatibility issue, a better way is to specify the Laravel version number.
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
The command generates an ImageUploadController.php file in the app/Http/Controllers directory. Open the file to add the following code:
namespace App\Http\Controllers; use Illuminate\Http\Request; use Validator; class ImageUploadController extends Controller function __construct() DBRInitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ= p">); DBRInitRuntimeSettingsWithString("\"ImageParameter\":<\"Name\":\"BestCoverage\",\"DeblurLevel\":9,\"ExpectedBarcodesCount\":512,\"ScaleDownThreshold\":100000,\"LocalizationModes\":[<\"Mode\":\"LM_CONNECTED_BLOCKS\">,,,,],\"GrayscaleTransformationModes\":[,]>>"); > function page() return view('barcode_qr_reader'); > function upload(Request $request) $validation = Validator::make($request->all(), [ 'BarcodeQrImage' => 'required' ]); if($validation->passes()) $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.' ]); > else return response()->json([ 'message' => $validation->errors()->all() ]); > > >
In __construct() method, you initialize the barcode SDK instance by setting a valid license key, which can be obtained from Dynamsoft customer portal. Calling DBRInitRuntimeSettingsWithString() is optional, because the default settings are suitable for most cases.
The uploaded images are saved to the public/images directory. The DecodeBarcodeFile() method is used to read barcode and QR code from the image file.
The next step is to create the barcode_qr_reader view.
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.
PHP Laravel Barcode QR Reader name="_token" content="" /> PHP Laravel Barcode QR Reader action="" method="post" enctype="multipart/form-data"> @csrf Select barcode image: type="file" name="BarcodeQrImage" id="BarcodeQrImage" accept="image/*"> type="submit" value="Read Barcode" name="submit"> 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 = e.target.result; > > fileReader.readAsDataURL(file); >
CSRF Protection is required for the form. A convenient way is to use the @csrf Blade directive to generate the hidden token input field:
action="" method="post" enctype="multipart/form-data"> @csrf .
As the web page is done, one more step is to add the web routes in public/routes/web.php .
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 http://127.0.0.1:8000/barcode_qr_reader in your browser.
PHP Barcode Generator and Reader API — Generate and Scan Barcodes in PHP
Barcodes are used to visually represent the data about an object in the machine-readable form. It is more popular to keep the data about products which can be read using the barcode scanners. In order to make it possible to generate and read a variety of barcodes in the PHP based web applications, we have released Aspose.BarCode for PHP via Java — an easy to use PHP barcode generator and reader API which is designed to work via Java Bridge.
In this article, I will present the recipes and code samples of how to generate and read the barcodes using PHP in your web applications. After reading this article, you’ll be able to:
PHP Barcode Generator and Reader — Installation and Usage#
The installation of Aspose.BarCode for PHP via Java consists of a few simple steps. The following are the pre-requisites of the API:
You can download the complete package containing the API’s JAR file, Java Bridge.jar, Java.inc, and ready to run source code examples to read, generate and recognize barcodes using PHP. In order to run the examples, following the below steps:
- Run JavaBridge server using run-bridge.bat (available in the package).
- Open doc/examples/php_side/how_to_generate_barcode_examples.php in the browser or run it using the command line.
Generate Barcodes using PHP Barcode Generator#
Once you have set up the environment, you can begin working with barcodes in your PHP based application. Aspose.BarCode for PHP via Java supports a variety of barcode symbologies including:
The following is the simple recipe to generate a barcode of any supported symbology using PHP:
- Create an object of BarcodeGenerator class and initialized it with the desired encoding type and code text.
- Generate barcode using BarcodeGenerator->save() method.
The following code sample shows how to generate a barcode using PHP.
Output#
Generate 2D Barcodes using PHP Barcode Generator#
Two-dimensional barcodes are represented as squares or the rectangles containing multiple dots. Aspose.BarCode for PHP via Java also supports various 2D barcode types such as QR, PDF417, etc. The following code sample shows how to generate a QR barcode using PHP:
Output#
Generate Barcodes with a Customized Appearance in PHP#
Aspose.BarCode for PHP via Java also lets you customize the appearance of the barcodes. For example, you can set the background, foreground or border color of the barcode. The following code sample shows how to generate a barcode with a customized appearance in PHP.
Output#
Generate Barcode with Caption in PHP#
You can also set as well as customize the appearance of the barcode’s caption. The following code sample shows how to set the barcode’s caption and customize its font.
Output#
Read a Barcode using PHP Barcode Reader#
Along with the barcode generator, the API also provides you a powerful barcode reader to scan the barcodes and extract the data. The following is the recipe for how to read a barcode.
- Create an instance of BarcodeReader and initialize it with the file’s path.
- Read barcode using BarcodeReader->read() method.
- Get barcode type and text using BarcodeReader->getCodeTypeName() and BarcodeReader->getCodeText() methods.
The following code sample shows how to read a barcode using PHP.
Read Barcode with a Particular Symbology using PHP Barcode Reader#
Barcode Recognition is the process of identifying the type of barcode we want to scan or read. In the previous example, we simply read a barcode without knowing its symbology type. However, in some cases, we know about the symbology of the barcode in advance. In such a scenario, we can speed up the scanning process by providing the barcode symbology explicitly to the barcode reader.
The following code sample shows how to read a barcode of a specific symbology using PHP.
Advanced Features of PHP Barcode Generator and Reader API#
Aspose.BarCode for PHP via Java provides a wide range of features for manipulating barcodes using PHP. You may have a look at the following documentation articles and simply port the Java code to PHP.
In case you would find anything confusing or difficult for you, feel free to contact us via our forum.
See Also#
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Read Barcode Scanner using php and mysql
License
milind001/barcode
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Read Barcode Scanner using php and mysql
This software can be used to scan products using barcode and keep the information about this product. It can be used to keep count of stocks in billing software(eg.Stock Management).
About
Read Barcode Scanner using php and mysql