国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

QRCode PHP生成二維碼類庫

Original 2016-10-21 13:42:09 615
abstract:使用類庫的方法include("Common/QRCode.class.php"); $QRCode= new QRCode(); $categoryList = $QRCode->getUrl();   以下是php生成二維碼完整類庫<?php   /**  * 類功能:將指

使用類庫的方法

include("Common/QRCode.class.php");
$QRCode= new QRCode();
$categoryList = $QRCode->getUrl();

   


以下是php生成二維碼完整類庫

<?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;
    }
 
    /**
     * 檢測存儲目錄是否存在,不存在則創(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;
        }
    }
 
}
 
?>

   


Release Notes

Popular Entries