zoukankan      html  css  js  c++  java
  • thinkphp 二维码封装函数

    一个二维码封装的thinkphp函数 Qrcode 类为开源生成的类 在 vendor目录下 需要注意的是时间每天生成的二维码 都放在当天的文件夹下 切记 [php] // 二维码函数 function qrcode($value,$errorCorrectionLevel, $matrixPointSize){ vendor('Qrcode.qrlib'); //$value 传入的值 //$filename 文件名称 //$errorCorrectionLevel 类型:L M Q H; //$matrixPointSize 大小 1 2 3 4 5 6 7 8 9 10 中的一个 //$info=QRcode::png($value,$filename,$errorCorrectionLevel, $matrixPointSize, 2); // $PNG_TEMP_DIR ='/Upload/'.'Qrcode'.'/'; //根据时间创建目录 每天创建一个 $time=date("Ymd",time()); $PNG_TEMP_DIR =$_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'Upload'.DIRECTORY_SEPARATOR.'qrcode'.DIRECTORY_SEPARATOR.$time.DIRECTORY_SEPARATOR; //$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR; //html PNG location prefix //$now=strtotime($time); //dump($time); $PNG_WEB_DIR = '/Upload/qrcode/'.$time.DIRECTORY_SEPARATOR; //include "qrlib.php"; //ofcourse we need rights to create temp dir if (!file_exists($PNG_TEMP_DIR)) mkdir($PNG_TEMP_DIR); $filename = $PNG_TEMP_DIR.'test.png'; //processing form input //remember to sanitize user input in real-life solution !!! $errorCorrectionLevel = $errorCorrectionLevel; $matrixPointSize = $matrixPointSize; if(isset($value)) { //it's very important! if (trim($value) == '') die('data cannot be empty! <a href="?">back</a>'); // user data $filename = $PNG_TEMP_DIR.'test'.md5($value.'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; $bb= QRcode::png($value, $filename, $errorCorrectionLevel, $matrixPointSize, 2); // dump($PNG_TEMP_DIR); // dump($bb); // dump($_SERVER['DOCUMENT_ROOT']); } else { echo '可能值为空所以生成失败!'; //default data // echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>'; // QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2); } // echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>'; $qrcode_path=$PNG_WEB_DIR.basename($filename); return $qrcode_path; } [/php]
  • 相关阅读:
    [PY3]——logging
    [PY3]——对iterator的处理(解析式、map、reduce、filter)
    php基础语法(文件加载和错误)
    php基础语法(控制语句、数组、函数)
    php基础语法(数据类型、运算符)
    php基础语法(变量)
    java基础语法
    ztree 获取根节点
    每天一个linux命令
    浅谈Web自适应
  • 原文地址:https://www.cnblogs.com/freefei/p/3234966.html
Copyright © 2011-2022 走看看