- 相关推荐
PHP学习:QRCode PHP生成二维码类库
在PHP语言中怎么生成二维码类库呢?下面就和小编一起来看看吧!希望对大家有用,更多内容请关注应届毕业生网!

使用类库的方法
|
1
2
3
|
include("Common/QRCode.class.php");$QRCode= new QRCode();$categoryList = $QRCode->getUrl(); |
以下是php生成二维码完整类库
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<?php /** * 类功能:将指定URL利用google api生成二维码保存到本地并返回本地访问url * author:252588119@qq.com * 使用方法见:http://liqingbo.cn/blog-435.html */class QRCode { private $path; private $size; public function __construct($path, $size) { $this->path = empty($path) ? C('webPath') . "/Uploads/QRCode/" : $path; $this->size = empty($size) ? 80 : $size; } /** * 检测存储目录是否存在,不存在则创建该目录 */ private function makeDir($path) { return is_dir($path) or ($this->makeDir(dirname($path)) and @mkdir($path, 0777)); } /** * 取得二维码地址 */ public function getUrl($url = "http://liqingbo.cn/blog-435.html") { $inPath = 'http://chart.apis.google.com/chart?chs=' . $this->size . 'x' . $this->size . '&cht=qr&chld=L|0&chl=' . $url; $savePath = $_SERVER['DOCUMENT_ROOT'] . $this->path; $this->makeDir($savePath); $fileName = substr(md5("$url"), 8, 16) . "_" . $this->size . ".png"; $savePath.=$fileName; $outUrl = "http://" . $_SERVER['HTTP_HOST'] . $this->path . $fileName; if (file_exists($savePath) && filesize($savePath) > 0) { return $outUrl; } $in = fopen($inPath, "rb"); $out = fopen($savePath, "wb"); while ($chunk = fread($in, 8192)) fwrite($out, $chunk, 8192); fclose($in); fclose($out); if (filesize($savePath) == 0) { $this->getUrl($url); } else { return $outUrl; } } } ?> |
【PHP学习:QRCode PHP生成二维码类库】相关文章:
PHP学习:PHP拼音类10-08
PHP学习:Category类库无限分类07-28
php生成带logo二维码方法08-27
PHP生成缩略图的类的方法07-11
如何生成静态页面的PHP类09-15
PHP封装数据库操作类08-17
20个PHP常用类库汇总09-27
PHP数据库操作类-ezSQL08-19
php学习之php配置07-15