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]
  • 相关阅读:
    LINQ标准查询操作符及例子(转载)
    Winform Combox 下拉模糊匹配
    在RowDataBound事件中取值的几种方法 转载
    shell脚本作业练习题8.6
    7.31.... 简单的python代码
    shell 脚本——第一节课 bash的基本特性
    shell 脚本——第二节课 重定向和管道符
    730
    应用范例:解析 Yahoo 奇摩股市的各档股票资讯HtmlAgilityPack
    微软一个罕为人知的无敌命令
  • 原文地址:https://www.cnblogs.com/freefei/p/3234966.html
Copyright © 2011-2022 走看看