在 Linux 上使用 PHP 和 LEADTOOLS Cloud Services 构建在线条形码阅读器
Dynamsoft 已经发布了 Linux 版本的条形码阅读器 SDK,支持使用 PHP 编程。 将 Dynamsoft 条形码阅读器集成到任何服务器端 Web 应用程序中非常方便。
引言
越来越多的人倾向于使用 Web 和云服务,例如 Google Cloud、Azure 和 AWS,因为不需要下载和安装应用程序。 可以通过 Web 浏览器访问各种软件和功能。 假设您想从头开始构建一个 Web 条形码阅读器即服务,Dynamsoft 条形码阅读器 SDK 将加快您的开发速度。
Dynamsoft 条形码阅读器 Linux 版本
支持的 Linux 操作系统(64 位)
- Ubuntu 14.04.4+ LTS、CentOS 7+、Debian 8+
支持的 Web 服务器
- Nginx、Apache 等。
支持的 PHP 版本
- 64 位 PHP 5.3、5.4、5.5、5.6,支持线程安全和非线程安全。
支持的 1D/2D 条码类型
- 1D:Code 39, Code 93, Code 128, Codabar, EAN-8, EAN-13, UPC-A, UPC-E, Interleaved 2 of 5 (ITF), Industrial 2 of 5 (Code 2 of 5 Industry, Standard 2 of 5, Code 2 of 5), ITF-14
- 2D:QRCode, DataMatrix 和 PDF417
支持的图像类型
- BMP、JPEG、PNG、GIF、TIFF 和 PDF
检测到的条码信息
- 条码类型
- 条形码计数
- 条码值(字符串形式)
- 条码原始数据(字节形式)
- 条码边界矩形
- 四个角的坐标
- 页码
特点
- 有效:读取一张图像中的多个条形码。
- 强大:读取质量差和损坏的条形码。
- 灵活:检测任何方向和旋转角度的条形码。
服务器端 PHP 条形码阅读器
Dynamsoft 条形码阅读器支持从 5.3 到 5.6 的 64 位 PHP。 因此,您需要首先检查系统上安装的 PHP 版本
php -v
除了 PHP 版本之外,您还需要知道 PHP 是否是线程安全的
php -i | grep Thread
将 Dynamsoft 条形码阅读器的共享库复制到 /usr/lib
sudo cp <Dynamsoft Barcode Reader>/lib/* /usr/lib
编辑 php.ini 以添加以下扩展路径
extension=<Dynamsoft Barcode Reader>/php/extension/<version>/<ts|nts>/php_DynamsoftBarcodeReader.so
使用 Form 将条形码图像上传到 Web 服务器
<form id="uploadForm" method="post" action="readbarcode.php" enctype="multipart/form-data"> <input type="file" id="upLoadFile" name="upLoadFile" class="ImgLocalPath" /> <input type="text" readonly="readonly" id="txtUploadFileName" class="radius3" /> <input type="button" id="btnUploadFile" value="Browse..." class="radius3 ml20"/> <input type="submit" id="btnReadBarcode" class="radius3 left ml20" value="Read Barcode" /> </form>
在服务器端检测条形码数据
<?php
include 'DynamsoftBarcodeReader.php';
ini_set('display_errors',1);
error_reporting(E_ALL);
$post_max_size = ini_get("post_max_size");
$maxsize = return_bytes($post_max_size);
if($_SERVER['CONTENT_LENGTH'] > $maxsize) {
echo "Post data size is bigger than " . $post_max_size;
exit;
}
$file = $_FILES["upLoadFile"]["tmp_name"];
if(!empty($file)){
readBarcode($file);
}
else {
echo "Fail to upload file.";
}
function readBarcode($path) {
try {
$br = new BarcodeReader();
} catch (exception $exp) {
echo 'Your barcode reader component is not registered correctly. Please refer to ReadMe.txt for details.<br/>';
exit;
}
$br->initLicense('693C401F1CC972A5018B729568B0CDD8');
try {
$br->decodeFile($path);
} catch(Exception $exp) {
echo $br->getErrorString() . '<br/>';
exit;
}
$cnt = $br->getBarcodesCount();
if($cnt > 0) {
echo 'Total barcode(s) found:' . $cnt . '.<br/>';
for ($i = 0; $i < $cnt; $i++) {
$result = $br->getBarcodeResult($i);
echo ($i+1) . ': ';
echo "$result->BarcodeFormatString, ";
echo "$result->BarcodeText<br/>";
}
}
else {
echo 'No barcodes found.<br/>';
}
}
?>
如何在 Ubuntu 上将示例代码部署到 Apache
安装 php5-curl、apache2 和 libapache2-mod-php5
sudo apt-get install php5-curl apache2 libapache2-mod-php5
解压该包并将项目复制到 /var/www/html/
sudo cp -r DecodeLocalFile /var/www/html
将扩展路径添加到 /etc/php5/apache2/php.ini。
启动 Apache 服务
sudo service apache2 start
在 Firefox 或 Chrome 中访问 https:///DecodeLocalFile/index.php。
在线演示
访问 PHP 条形码阅读器 体验在线演示。
获取 SDK 和示例
您是否想在 Linux 上用 PHP 构建一个服务器端条形码阅读器?现在就开始动手吧
同时,您可以从以下位置获得大量代码示例
超越桌面条形码 SDK
除了桌面平台 - Windows、Linux 和 Mac OS X,Dynamsoft 条形码阅读器 SDK 还将在不久的将来支持 Raspberry Pi、Android 和 iOS。请继续关注 Dynamsoft 条形码阅读器页面 和 Dynamsoft labs。如果您对 IoT 和 移动 SDK 感兴趣,请联系 support@dynamsoft.com 以获取预览版本。