如何将使用phpqrcode生成的qrcode存储到数据库中,而不是存储在文件路径中? [英] How do I store the qrcode generated using phpqrcode into a db instead of in a filepath?

查看:49
本文介绍了如何将使用phpqrcode生成的qrcode存储到数据库中,而不是存储在文件路径中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将qrcode(使用phpqrcode生成)存储到数据库中,而不是将它们放在文件路径中。 SourceForge项目中给出的示例(http://phpqrcode.sourceforge.net/examples/)只谈到将它们存储在物理文件路径中。我不想将它们存储在文件路径中。 请指教。

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

推荐答案

基于与OP的评论中的讨论,以及前面提到的问题-如何将二维码生成为ASCII码-此主题在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;' 
)); 

完成这些步骤后,代码的ASCII图形表示将存储在$raw中;您可以将其存储在数据库中、显示给客户端或通过电子邮件发送。

如果您确实通过电子邮件发送,我建议将<br/>替换为 ,并确保电子邮件的编码设置为UTF-8,以便字符正确显示。

这篇关于如何将使用phpqrcode生成的qrcode存储到数据库中,而不是存储在文件路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆