在Linux上搭建PHP条形码阅读器
来源:互联网 发布:个人可以注册cn域名吗 编辑:程序博客网 时间:2024/06/05 17:25
无论你是一个开发者还是一个用户,你都或许听说过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版本:
1
php -v
在确认了PHP版本之后,你还需要知道你的PHP是否是线性安全的:
1
php –i | grep Thread
复制Dynamsoft Barcode Reader库到/usr/lib:
1
sudo
cp
/lib/
*
/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"
>
6
7
</
form
>
在服务端检测条形码数据:
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
);
06
07
if
(
$_SERVER
[
'CONTENT_LENGTH'
] >
$maxsize
) {
08
echo
"Post data size is bigger than "
.
$post_max_size
;
09
exit
;
10
}
11
12
$file
=
$_FILES
[
"upLoadFile"
][
"tmp_name"
];
13
if
(!
empty
(
$file
)){
14
readBarcode(
$file
);
15
}
16
else
{
17
echo
"Fail to upload file."
;
18
}
19
20
function
readBarcode(
$path
) {
21
try {
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>'
;
25
exit
;
26
}
27
28
$br
->initLicense(
'693C401F1CC972A5018B729568B0CDD8'
);
29
30
try {
31
$br
->decodeFile(
$path
);
32
} catch(Exception
$exp
) {
33
echo
$br
->getErrorString() .
'<br>'
;
34
exit
;
35
}
36
37
$cnt
=
$br
->getBarcodesCount();
38
if
(
$cnt
> 0) {
39
echo
'Total barcode(s) found:'
.
$cnt
.
'.<br>'
;
40
for
(
$i
= 0;
$i
<
$cnt
;
$i
++) {
41
$result
=
$br
->getBarcodeResult(
$i
);
42
echo
(
$i
+1) .
': '
;
43
echo
"$result->BarcodeFormatString, "
;
44
echo
"$result->BarcodeText<br>"
;
45
}
46
}
47
else
{
48
echo
'No barcodes found.<br>'
;
49
}
50
}
如何在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
Demo和源码
点击PHP Barcode Reader 查看demo.
点击这里下载源码。
来自:PHPChina
0 0
- 在Linux上搭建PHP条形码阅读器
- 在 Linux 上安装 chm 文件阅读器
- 在Linux上搭建WEB服务器:基本概念、PHP zt
- 在Linux上搭建WEB服务器:基本概念、PHP zt
- Apache,PHP,MySQL为什么要在Linux上搭建
- TConnector条形码阅读器
- 在网页上生成条形码
- 在linux上搭建gtest
- 在linux上搭建gtest
- 在Linux上搭建mycat
- 在linux上odoo搭建
- 在Linux上搭建JSP运行环境(Linux+Apache+PHP+JSP)
- 在windows上搭建php oauth支持
- 在CentOS上搭建PHP服务器环境
- 在ubuntu上搭建apache+php+mysql
- 在CentOS上搭建PHP服务器环境
- 在MAC上搭建webpagetest安装php
- 在CentOS上搭建PHP服务器环境
- 给织梦DedeCms文章页加上百度、谷歌搜索本篇文章功能
- Tomcat学习之Acceptor
- POJ 2686 - Y2K Accounting Bug
- 在织梦DedeCms的搜索框里显示提示信息
- UEditor学习笔记(二)
- 在Linux上搭建PHP条形码阅读器
- 进入织梦DedeCms数据库删除指定IP的所有评论
- Strategy模式
- 大话数据结构 -- 第九章 排序
- 织梦DedeCms获取文章URL地址的方法
- 移动互联网时代的创业生存法则:快速试错,廉价失败
- Tomcat学习之Request/Response封装
- hdu 1584 蜘蛛牌(dfs)
- 织梦DedeCms鼠标移到标题处显示完整标题