- 相關(guān)推薦
PHP學(xué)習(xí):QRCode PHP生成二維碼類(lèi)庫(kù)
在PHP語(yǔ)言中怎么生成二維碼類(lèi)庫(kù)呢?下面就和小編一起來(lái)看看吧!希望對(duì)大家有用,更多內(nèi)容請(qǐng)關(guān)注應(yīng)屆畢業(yè)生網(wǎng)!

使用類(lèi)庫(kù)的方法
|
1
2
3
|
include("Common/QRCode.class.php");$QRCode= new QRCode();$categoryList = $QRCode->getUrl(); |
以下是php生成二維碼完整類(lèi)庫(kù)
|
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 /** * 類(lèi)功能:將指定URL利用google api生成二維碼保存到本地并返回本地訪(fǎng)問(wèn)url * author:252588119@qq.com * 使用方法見(jiàn):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; } /** * 檢測(cè)存儲(chǔ)目錄是否存在,不存在則創(chuàng)建該目錄 */ 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學(xué)習(xí):QRCode PHP生成二維碼類(lèi)庫(kù)】相關(guān)文章:
PHP學(xué)習(xí):PHP拼音類(lèi)10-08
PHP學(xué)習(xí):Category類(lèi)庫(kù)無(wú)限分類(lèi)07-28
php生成帶logo二維碼方法08-27
PHP生成縮略圖的類(lèi)的方法07-11
如何生成靜態(tài)頁(yè)面的PHP類(lèi)09-15
PHP封裝數(shù)據(jù)庫(kù)操作類(lèi)08-17
20個(gè)PHP常用類(lèi)庫(kù)匯總09-27
PHP數(shù)據(jù)庫(kù)操作類(lèi)-ezSQL08-19
php學(xué)習(xí)之php配置07-15