在Linux上搭建PHP条形码阅读器

无论你是一个开发者还是一个用户,你都或许听说过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.

点击这里下载源码。

转载于:https://my.oschina.net/u/2898364/blog/847952

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值