How to output thinkphp QR code to a template file

Source: Internet
Author: User
Directly look at the code. This is the code in thinkphp to generate a QR code {code ...} this is the code & amp; lt; body & amp; gt; & amp; lt; divclass & quot; img & quot; & amp; gt; & amp; lt; imgalt & quot; QR code & quot; src & quot; index. phpRecrecommend & quot; & amp; gt; & amp; lt; div & amp; gt; & amp; lt; body & amp; gt...

View Code directly

This is the QR code generated by the code in thinkphp.

$ Model = M ("member"); $ rs = $ model-> where ("tmId ". $ tmId)-> find (); // generate the QR code vendor ("phpqrcode. phpqrcode "); $ path = 'public/qrcode/'; mkdir ($ path); then qr?#path.'qrcode.png'; $ text =" http://www.xghm.com.cn/index.php/Login/reg/tmTel ". $ rs ['tmtel']; $ size = '4'; $ level = 'l'; $ padding = 2; $ logo = false; QRcode: png ($ text, $ QR, $ level, $ size, $ padding); $ this-> display ();

This is the code in the template.






However, the output result is as follows:

Where is the problem ??

Reply content:

View Code directly

This is the QR code generated by the code in thinkphp.

$ Model = M ("member"); $ rs = $ model-> where ("tmId ". $ tmId)-> find (); // generate the QR code vendor ("phpqrcode. phpqrcode "); $ path = 'public/qrcode/'; mkdir ($ path); then qr?#path.'qrcode.png'; $ text =" http://www.xghm.com.cn/index.php/Login/reg/tmTel ". $ rs ['tmtel']; $ size = '4'; $ level = 'l'; $ padding = 2; $ logo = false; QRcode: png ($ text, $ QR, $ level, $ size, $ padding); $ this-> display ();

This is the code in the template.






However, the output result is as follows:

Where is the problem ??

Remove the last $ this-> display ();. It is best to add ob_clean () before generating the image ()
I have a similar method in my code.

public function qrcode($guid) {        vendor("phpqrcode.phpqrcode");        //$data = "http://www.baidu.com";        $url="http://".$_SERVER['HTTP_HOST'].U('Urlhandle/show',array('guid'=>$guid),$domin=true);        $level = 'L';        $size = 8;        ob_clean();        \QRcode::png($url,false,$level,$size);    }

Effect you can go to http://www.wx2share.com to see

We recommend that you use the phpqrcode plug-in to generate a QR code.

public function qrcode($text='https://www.baidu.com',$level=3,$size=4){    $text=$this->$_get['text']?$this->$_get['text']:$text;    $size=$this->$_get['size']?$this->$_get['size']:$size;    $level=$this->$_get['level']?$this->$_get['level']:$level;    Vendor('phpqrcode.phpqrcode');    $object = new \QRcode();    $object->png($text, false, $level, $size, 2);}

The Landlord seems to be confused.
The first is the QR code, which requires an independent action.
Display interface, which is another action
For example:

Public function action1 () {$ this-> display ();} public function action2 (){............ QRcode: png ($ text, $ QR, $ level, $ size, $ padding);} in the template:

Then access action1.

Generate a separate method and use src of the img label to access this method,

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.