How do I store the qrcode generated using phpqrcod

2020-08-04 10:51发布

问题:

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.



标签: php qr-code