Home  >  Article  >  Backend Development  >  Use Thinkphp3.2 combined with phpqrcode to generate QR code

Use Thinkphp3.2 combined with phpqrcode to generate QR code

一个新手
一个新手Original
2017-09-28 10:15:552412browse

First, download phpqrcode and extract it to the project ThinkPHP\Library\Vendor directory.
Index_index.html (the template can be configured by yourself)


    尺寸大小:
            
    边距大小:
         
            1px
            2px
            3px
            5px
        
    容错级别:
        
        Low (7%)
        Medium (15%)
        Quartile (25%)
        High (30%)
        
    二维码内容:
            
    二维码logo:

Controller: IndexController.class.php


 3145728, 'rootPath' => './upload/', 'savePath' => '', 'saveName' => array('uniqid',''), 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => true, 'subName' => array('date','Ymd'), );
    $upload = new \Think\Upload($config);
    // 实例化上传类 // 上传单个文件 $info = $upload->uploadOne($_FILES['test']);
    if(!$info) {
    // 上传错误提示错误信息 $qrcode_path_new = './Public/Home/images/code'.'_'.date("Ymdhis").'.png';
    $content = $_POST['content'];
    $matrixPointSize = $_POST['matrixPointSize'];
    $matrixMarginSize = $_POST['matrixMarginSize'];
    $errorCorrectionLevel = $_POST['errorCorrectionLevel'];
    makecode_no_pic($content,$qrcode_path_new,$matrixPointSize,$matrixMarginSize,$errorCorrectionLevel);
    $this->assign('img',$qrcode_path_new);
}
else {
    $qrcode_path = "./upload/".$info['savepath'].$info['savename'];
    $content = $_POST['content'];
    $matrixPointSize = $_POST['matrixPointSize'];
    $matrixMarginSize = $_POST['matrixMarginSize'];
    $errorCorrectionLevel = $_POST['errorCorrectionLevel'];
    $url = "./upload/qrcode/".date("YmdHis").".png";
    makecode($qrcode_path,$content,$matrixPointSize,$matrixMarginSize,$errorCorrectionLevel,$url);
    $this->assign('img',$url);
}
$this->display();
}
}

Then create a new function.php under the project Application/Home/Common


When there is no picture uploaded, the QR code generated is just a simple QR code. Only when a logo is uploaded, the QR code with the logo will be generated.

The picture below is the QR code generated when there is no logo:

The picture below is The QR code generated when a picture is uploaded:

The above is the detailed content of Use Thinkphp3.2 combined with phpqrcode to generate QR code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn