QRCode PHP生成二维码类库

使用类库的方法

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

以下是php生成二维码完整类库

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;
        }
    }

}

?>

温馨提示: 本文最后更新于2024-12-31 21:02:52,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 蚂蚁官方
© 版权声明
THE END
喜欢就支持一下吧
点赞13赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容