- 相關推薦
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