使用phpqrcode生成二维码
最近在做一个分销系统时需要生成链接的二维码,使用了phpqrcode来生成,发现有些小问题记录一下
- phpqrcode的使用方法
qrcode的使用方法在网上很多,百度一下就有了
下这个是我从网上找的,需要注意一下的是他不会自动帮你创建文件夹,所以得事先创建好文件夹,否则会创建失败
// 1. 生成原始的二维码(生成图片文件)
function scerweima($url=''){
require_once 'phpqrcode.php';
$value = $url; //二维码内容
$errorCorrectionLevel = 'L'; //容错级别
$matrixPointSize = 5; //生成图片大小
//生成二维码图片
$filename = 'qrcode/'.microtime().'.png';
QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);
$QR = $filename; //已经生成的原始二维码图片文件
$QR = imagecreatefromstring(file_get_contents($QR));
//输出图片
imagepng($QR, 'qrcode.png');
imagedestroy($QR);
return '<img src="qrcode.png" alt="使用微信扫描支付">';
}
//调用查看结果
echo scerweima('https://www.baidu.com');
如果要提供下载使用下面的方法,使用header的方法需要前面不能有任何内容,所以在这使用ob_end_clean()清空缓冲区并关闭缓存,如果header前面有内容的话下载下来的图片是错误的
ob_end_clean();
header("content-disposition:attachment;filename=mqrcode.png");
header("content-length:".filesize($filename));
readfile($filename);
网友评论