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

时间:2013-08-27 11:37:54

标签: php qr-code

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

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

1 个答案:

答案 0 :(得分:1)

基于对OP的评论中的讨论,以及如何准确的问题 - 如何将QR代码生成为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/>替换为\n,并确保将电子邮件的编码设置为UTF-8,以便正确显示字符。