• 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]
  • 相关阅读:
    队列

    Oracle 12c新特性之——TABLE ACCESS BY INDEX ROWID BATCHED
    连续三月涨势明显,PostgreSQL 将崛起?
    Oracle物理DG自动切换——Dataguard Broker配置
    MSSQL索引视图(indexed view)之简述及使用
    连续三月涨势明显,PostgreSQL 将崛起?
    Scheduler & Task & Worker & Thread & Request & Session & Connection of SQL Server
    MSSQL内存架构及管理
    MSSQL数据库后台进程(线程)
  • 原文地址:https://www.cnblogs.com/freefei/p/3234966.html
Copyright © 2020-2023  润新知