無論你是一個開發者還是一個用戶,你都或許聽說過SaaS、Paas、laaS這些詞。這是三個不同的雲端模型。爲什麼越來越多的人都來擁抱類似於Google Cloud,Azure和AWS這樣的雲服務端?因爲使用這些雲服務器不需要下載應用,也不需要安裝。大量的軟件和應用已經可以通過B\S端實現。假設你現在想要搭建一個基於WEB的條形碼閱讀器,使用Dynamsoft
Barcode Reader SDK可以加快你的開發進程。
下載SDK
條形碼閱讀器的PHP服務端
Dynamsoft Barcode Reader 支持 64-bit位的 PHP 5.3 到 5.6版本。 因此,首先你需要檢查安裝在你係統中的PHP版本:
在確認了PHP版本之後,你還需要知道你的PHP是否是線性安全的:
複製Dynamsoft Barcode Reader庫到/usr/lib:
編輯php.ini:
1
|
extension= /php/extension/ / /php_DynamsoftBarcodeReader .so
|
通過表單上傳條形碼圖片到服務器:
1 |
< form id = "uploadForm" method = "post" action = "readbarcode.php" enctype = "multipart/form-data" > |
2 |
< input type = "file" id = "upLoadFile" name = "upLoadFile" class = "ImgLocalPath" > |
3 |
< input type = "text" readonly = "readonly" id = "txtUploadFileName" class = "radius3" > |
4 |
< input type = "button" id = "btnUploadFile" value = "Browse..." class = "radius3
ml20" > |
5 |
< input type = "submit" id = "btnReadBarcode" class = "radius3
left ml20" value = "Read
Barcode" > |
在服務端檢測條形碼數據:
01 |
include 'DynamsoftBarcodeReader.php' ; |
02 |
ini_set ( 'display_errors' ,1); |
03 |
error_reporting (E_ALL); |
04 |
$post_max_size = ini_get ( "post_max_size" ); |
05 |
$maxsize =
return_bytes( $post_max_size ); |
07 |
if ( $_SERVER [ 'CONTENT_LENGTH' ]
> $maxsize )
{ |
08 |
echo "Post
data size is bigger than " . $post_max_size ; |
12 |
$file = $_FILES [ "upLoadFile" ][ "tmp_name" ]; |
17 |
echo "Fail
to upload file." ; |
20 |
function readBarcode( $path )
{ |
22 |
$br = new BarcodeReader(); |
23 |
}
catch (exception $exp )
{ |
24 |
echo 'Your
barcode reader component is not registered correctly. Please refer to ReadMe.txt for details.<br>' ; |
28 |
$br ->initLicense( '693C401F1CC972A5018B729568B0CDD8' ); |
31 |
$br ->decodeFile( $path ); |
32 |
}
catch(Exception $exp )
{ |
33 |
echo $br ->getErrorString()
. '<br>' ; |
37 |
$cnt = $br ->getBarcodesCount(); |
39 |
echo 'Total
barcode(s) found:' . $cnt . '.<br>' ; |
40 |
for ( $i =
0; $i < $cnt ; $i ++)
{ |
41 |
$result = $br ->getBarcodeResult( $i ); |
43 |
echo "$result->BarcodeFormatString,
" ; |
44 |
echo "$result->BarcodeText<br>" ; |
48 |
echo 'No
barcodes found.<br>' ; |
如何在Ubuntu的Apache上部署示例代碼
安裝php5-curl, apache2 和 libapache2-mod-php5:
1
|
sudo
apt-get install
php5-curl apache2 libapache2-mod-php5
|
提取代碼文件複製到 /var/www/html/:
1
|
sudo
cp
-r DecodeLocalFile /var/www/html
|
增加擴展路徑到 /etc/php5/apache2/php.ini.
開啓Apache服務:
1 |
sudo service
apache2 start |
在瀏覽器訪問http://localhost/DecodeLocalFile/index.php