无论你是一个开发者还是一个用户,你都或许听说过SaaS、Paas、laaS这些词。这是三个不同的云端模型。为什么越来越多的人都来拥抱类似于Google Cloud,Azure和AWS这样的云服务端?因为使用这些云服务器不需要下载应用,也不需要安装。大量的软件和应用已经可以通过B\S端实现。假设你现在想要搭建一个基于WEB的条形码阅读器,使用Dynamsoft Barcode Reader SDK可以加快你的开发进程。
下载SDK
Dynamsoft Barcode Reader 30-day Free Trial
条形码阅读器的PHP服务端
Dynamsoft Barcode Reader 支持 64-bit位的 PHP 5.3 到 5.6版本。 因此,首先你需要检查安装在你系统中的PHP版本:
php -v
在确认了PHP版本之后,你还需要知道你的PHP是否是线性安全的:
php –i | grep Thread
复制Dynamsoft Barcode Reader库到/usr/lib:
sudo cp /lib/* /usr/lib
编辑php.ini:
extension=/php/extension/php_DynamsoftBarcodeReader.so
通过表单上传条形码图片到服务器:
<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="ReadBarcode">
</form>
在服务端检测条形码数据:
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 "Postdata 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
在浏览器访问http://localhost/DecodeLocalFile/index.php
Demo和源码
点击PHP Barcode Reader 查看demo.
点击这里下载源码。