简体   繁体   English

如何将使用phpqrcode生成的qrcode存储到数据库而不是文件路径中?

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

I need to store the qrcode (generated using phpqrcode) into a db instead of placing them in a filepath. 我需要将qrcode(使用phpqrcode生成)存储到db中,而不是将它们放在文件路径中。 The examples given in the sourceforge project ( http://phpqrcode.sourceforge.net/examples/ ) speaks only about storing them in a physical file path. sourceforge项目( http://phpqrcode.sourceforge.net/examples/ )中给出的示例仅涉及将其存储在物理文件路径中的内容。 I dont want to store them in a file path. 我不想将它们存储在文件路径中。 Please advice. 请指教。

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

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: 基于与OP的注释中的讨论以及精确的问题-如何以ASCII格式生成QR码-该主题在phpqrcode的示例中进行了介绍:

http://phpqrcode.sourceforge.net/examples/index.php?example=702 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 ; 完成这些步骤后,代码的ASCII美术表示形式存储在$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. 如果确实要通过电子邮件发送,则建议将<br/>替换为\\n并确保将电子邮件的编码设置为UTF-8,以便正确显示字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM