我想在mysql数据库中生成并存储QR码图像,以便稍后通过电子邮件发送。我尝试了以下代码:
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();
}
但$var
包含错误数据。
有什么方法可以实现我想要做的事情?提前谢谢。
答案 0 :(得分:1)
您可以base64 encode输出数据并存储,然后在使用前再次解码:
$result = base64_encode(file_get_contents("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=$person_id"));
// store $result in your DB
然后从数据库中检索后:
// get result from your DB
header('Content-Type: image/png');
echo base64_decode($dbResult);