Enable COM support in PHP
From PHP 5.4.5, COM and DOTNET is no longer built into the PHP core.
You have to add COM support by inserting this line in php.ini:
extension = php_com_dotnet.dll
Otherwise you will see an error in your error log:
Fatal error: Class 'COM' not found
Installation of Dynamsoft Barcode Reader
Download one of our PHP samples from Code Gallery
In the sample directory, you will find the following files:
- {Sample Directory}\ActiveX\register.bat
- {Sample Directory}\DynamsoftBarcodeReader.php
Please run the register.bat file as administrator to register the required barcode reader DLL.
Code Snippet
Step 1.
Suppose you are creating a project in a folder called test. In the folder, create a test.php file and a readbarcode.php file. Also, copy the aforementioned dynamsoftbarcodereader.php file from the SDK package to the test folder.
Edit the test.php as follows:
<html>
<head />
<body>
<h1>Dynamsoft Barcode Reader PHP Simple Sample</h1>
<form action="readbarcode.php" method="post" enctype="multipart/form-data">
Select barcode image:
<input type="file" name="barcodefile" id="barcodefile" accept="image/*" /><br/>
<type="submit" value="Read Barcode" name="submit" />
</form>
</body>
</html>
Step 2.
Then edit the readbarcode.php file. Please update <your license key here> and <your image file here> with valid values in the code respectively. You may log in the customer portal and request for a trial extension online.
<?php
include "dynamsoftbarcodereader.php";
$uploadfile = $_FILES["barcodefile"]["tmp_name"];
$br = new BarcodeReader("<your license key here>");
$resultAry = $br->decodeFile("<your image file here>", "");
$cnt = count($resultAry);
if($cnt > 0){
echo "Barcode Count: $cnt <br />";
for ($i = 0; $i < $cnt; $i++) {
$res = $resultAry[$i];
echo "$i. $res->BarcodeFormatString , $res->BarcodeText<br />";
}
}
?>
Step 3.
Visit http://[ip]:[port]/test/test.php to verify if it works.