I want to generate and store QR code image in mysql database in order to send it by e-mail later. I tried the following code:
function generateQRCode($person_id)
{
ob_start();
$var=file_get_contents("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=$person_id");
ob_end_clean();
}
but $var
contains bad data.
What are the ways to achieve what I'm trying to do? Thanks in advance.
You can base64 encode the output data and store that, then just decode it again before use:
$result = base64_encode(file_get_contents("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=$person_id"));
// store $result in your DB
Then after retrieving from the database:
// get result from your DB
header('Content-Type: image/png');
echo base64_decode($dbResult);