下載擴展
https://github.com/love1314-ball/phpqrcode
下載後放在vendor文件中就行了(名字要正確)
可以將二維碼通過瀏覽器下載,我將二維碼存在我們項目中的文件夾中了。
<?php
namespace app\index\controller;
use app\common\controller\IndexBase;
use think\Db;
use think\Request;
class Appointment extends IndexBase
{
public function qrcode($order) {
$request = Request::instance();
header( 'Content-Type: text/html;charset=utf-8' );
//引入二維碼生成插件
vendor( 'phpqrcode.phpqrcode' );
// 生成的二維碼所在目錄+文件名
$path = 'static/QRcode/';
//生成的二維碼所在目錄
if ( !file_exists( $path ) ) {
mkdir( $path, 0700, true );
}
$time = time().'.png';
//生成的二維碼文件名
$fileName = $path.$time;
//1.拼裝生成的二維碼文件路徑
$data = 'http://www.tp5-appointment.com/index/mi/destroy?orderid='.$order;
//2.生成二維碼的數據( 掃碼顯示該數據 )
$level = 'L';
//3.糾錯級別:L、M、Q、H
$size = 10;
//4.點的大小:1到10, 用於手機端4就可以了
ob_end_clean();
//清空緩衝區
\QRcode::png( $data, $fileName, $level, $size );
//生成二維碼
//文件名轉碼
$file_name = iconv( 'utf-8', 'gb2312', $time );
$file_path = $request->domain().'/'.$fileName;//插入數據庫的字段
return $file_path;
// dump($file_path);
// exit;
//獲取下載文件的大小
// $file_size = filesize( $file_path );
// $file_temp = fopen ( $file_path, 'r' );
//返回的文件
// header( 'Content-type:application/octet-stream' );
// //按照字節大小返回
// header( 'Accept-Ranges:bytes' );
// //返回文件大小
// header( 'Accept-Length:'.$file_size );
// //這裏客戶端的彈出對話框
// header( 'Content-Disposition:attachment;filename='.$time );
// echo fread ( $file_temp, filesize ( $file_path ) );
// fclose ( $file_temp );
// exit ();
}
}