php生成二维码的插件phpqrcode

参考网址:

http://www.thinkphp.cn/topic/7749.html

http://blog.csdn.net/stxyc/article/details/44650971

php生成二维码的几种方式方法:http://blog.csdn.net/small_rice_/article/details/22922455

我用的是thinkphp框架

第一步:导入插件,把phpqrcode解压到thinkphp专门摆放第三方插件的地方,我这个项目的是ThinkPHP\Library\Vendor,官方的是:ThinkPHP/Extend/Vendor

第二步:在common/function.php公用函数中添加一个调用函数:

function qrcode($text=""){
    //include(realpath('D:\phpStudy\WWW\phpqrcode\qrlib.php'));
    //include(realpath('D:\phpStudy\WWW\phpqrcode\phpqrcode.php'));
    vendor("phpqrcode.phpqrcode");
     $data = $text;
     $filename =dirname( dirname(dirname( dirname( __FILE__ ) )) )."\Uploads\qrcode\z"
         .md5($data).".png";
     $errorCorrectionLevel = 'L';
     $matrixPointSize = 2;
     $margin = 5;
    // import("Common.Extend.phppqrcode",'phpqrcode','.php');
    QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, $margin);
    return "/Uploads/qrcode/z".md5($data).".png";
}

 

 第三步:在控制器函数用调用该公共函数

//生成二维码
        $text= "http://".I( 'server.HTTP_HOST' ).'/Home/Login/register?id='.$userData['ue_id'];
        $erweima=qrcode($text);
        $this->assign('erweima',$erweima);

 第四步:在模板文件中调用

<img src="{$erweima}" alt="">

效果图:

 

注意的问题:

1.插件的引入一定要对,可以用include

2. $filename这个地址很重要,可能是物理地址。

3.return的地址和$filename有关联,写法又不一样。

出问题的话基本都是这三个地址没填好。

posted @ 2016-03-18 10:02  绿尘枫  阅读(2610)  评论(0编辑  收藏  举报