How do I store the qrcode generated using phpqrcode into a db instead of in a filepath?

元气小坏坏 提交于 2020-01-01 22:04:19

问题


I need to store the qrcode (generated using phpqrcode) into a db instead of placing them in a filepath. The examples given in the sourceforge project (http://phpqrcode.sourceforge.net/examples/) speaks only about storing them in a physical file path. I dont want to store them in a file path. Please advice.

QRcode::png($codecontent, $filepath);

回答1:


Based on the discussion in comments with the OP, and the question as precised - how to generate the QR code as ASCII - this topic is covered in the examples for phpqrcode:

http://phpqrcode.sourceforge.net/examples/index.php?example=702

$codeContents = '12345'; // what to store

// generates the contents as array
// elements of array contain lines of the QR code
// lines are comprised of ones and zeros
$text = QRcode::text($codeContents);

// here array is joined, putting <br/> at end of lines
// for HTML display
$raw = join("<br/>", $text); 

// 1s and 0s are converted to "blocky" characters
// so that display is more like QR code and less like stream of 101010
$raw = strtr($raw, array( 
    '0' => '<span style="color:white">&#9608;&#9608;</span>', 
    '1' => '&#9608;&#9608;' 
)); 

After these steps, an ASCII art representation of the code is stored in $raw; you could store that in a database, show to a client, or send over e-mail.

If you do send it in an e-mail, I'd suggest replacing <br/> with \n and ensuring that the email's encoding is set to UTF-8 so that the characters show up properly.



来源:https://stackoverflow.com/questions/18464325/how-do-i-store-the-qrcode-generated-using-phpqrcode-into-a-db-instead-of-in-a-fi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!