首先,下载phpqrcode,将其解压到项目thinkphp\library\vendor目录下。
index_index.html(模板可自行配置)
尺寸大小:
边距大小:
1px
2px
3px
5px
容错级别:
Low (7%)
Medium (15%)
Quartile (25%)
High (30%)
二维码内容:
二维码logo:控制器:IndexController.class.php
3145728, 'rootPath' => './upload/', 'savePath' => '', 'saveName' => array('uniqid',''), 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => true, 'subName' => array('date','Ymd'), );
$upload = new \Think\Upload($config);
// 实例化上传类 // 上传单个文件 $info = $upload->uploadOne($_FILES['test']);
if(!$info) {
// 上传错误提示错误信息 $qrcode_path_new = './Public/Home/images/code'.'_'.date("Ymdhis").'.png';
$content = $_POST['content'];
$matrixPointSize = $_POST['matrixPointSize'];
$matrixMarginSize = $_POST['matrixMarginSize'];
$errorCorrectionLevel = $_POST['errorCorrectionLevel'];
makecode_no_pic($content,$qrcode_path_new,$matrixPointSize,$matrixMarginSize,$errorCorrectionLevel);
$this->assign('img',$qrcode_path_new);
}
else {
$qrcode_path = "./upload/".$info['savepath'].$info['savename'];
$content = $_POST['content'];
$matrixPointSize = $_POST['matrixPointSize'];
$matrixMarginSize = $_POST['matrixMarginSize'];
$errorCorrectionLevel = $_POST['errorCorrectionLevel'];
$url = "./upload/qrcode/".date("YmdHis").".png";
makecode($qrcode_path,$content,$matrixPointSize,$matrixMarginSize,$errorCorrectionLevel,$url);
$this->assign('img',$url);
}
$this->display();
}
}然后在项目Application/Home/Common下新建function.php
在没有图片上传的情况下,生成我二维码只是单纯的二维码,只有在有logo上传的时候,才会生成带logo的二维码。
如下图,即没有logo时生成的二维码:
立即学习“PHP免费学习笔记(深入)”;
下图即在有图片被上传的时候生成的二维码:













