Thinkphp3.2 version combined with Phpqrcode to generate QR code and provide download

Source: Internet
Author: User

Description: This article is mainly for you to introduce the Thinkphp3.2.3 integrated Phpqrcode generation with two-dimensional code implementation method and provide image download, interested in the small partners can refer to

Reason: thinkphp has no QR code related libraries, so we can integrate phpqrcode to achieve the function of generating QR code.

First, phpqrcode:http://phpqrcode.sourceforge.net/

Drop Location: thinkphp/vendor/directory, such as

Second, write code

HTML code

<! DOCTYPE html>

PHP code

<?php/*time:2018-01-08 23:10
Updatetime:2018-05-09user:shenlinpurpose: QR code */namespace test\controller;use think\controller;class EwmController Extends Controller {public Function index () {if (Is_ajax) {//Receive Url$url = I (' Get.url '); $UrlInfo = $this->qrcode ($url); if ($UrlInfo) {$data [' info '] = "build succeeded"; $data [' status '] = 1; $data [' url '] = $UrlInfo;} else{$data [' info '] = "Build failed! "; $data [' status '] = 0;} $this->ajaxreturn ($data);} else{$this->display ();} Public Function QRCode ($url) {Ob_clean (); Vendor (' Phpqrcode.phpqrcode '); $level = 3; $size = 4; $errorCorrectionLevel = Intval ($level);//fault tolerance level $matrixPointSize = Intval ($size);//Generate picture size//save location $path = "public/qrcode/"; The generated file name $fileName = $path. Date (' Ymdhis ', Time ()). PNG '; Generate QR code image $object = new \qrcode (); $object->png ($url, $fileName, $errorCorrectionLevel, $matrixPointSize, 2); return $fileName; }}

Third, the perfect end, if you need to generate a logo with the QR Code, please refer to the article "Thinkphp3.2 version combined with Phpqrcode to generate a logo with the QR code and provide download"

Thinkphp3.2 version combined with Phpqrcode to generate QR code and provide download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.