]>
Raphaƫl G. Git Repositories - cdn/blob - vendor/phpqrcode/index.php
   7  * PHP QR Code is distributed under LGPL 3 
   8  * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> 
  10  * This library is free software; you can redistribute it and/or 
  11  * modify it under the terms of the GNU Lesser General Public 
  12  * License as published by the Free Software Foundation; either 
  13  * version 3 of the License, or any later version. 
  15  * This library is distributed in the hope that it will be useful, 
  16  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
  18  * Lesser General Public License for more details. 
  20  * You should have received a copy of the GNU Lesser General Public 
  21  * License along with this library; if not, write to the Free Software 
  22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
  25     echo "<h1>PHP QR Code</h1><hr/>"; 
  27     //set it to writable location, a place for temp generated PNG files 
  28     $PNG_TEMP_DIR = dirname(__FILE__
).DIRECTORY_SEPARATOR
.'temp'.DIRECTORY_SEPARATOR
; 
  30     //html PNG location prefix 
  31     $PNG_WEB_DIR = 'temp/'; 
  35     //ofcourse we need rights to create temp dir 
  36     if (!file_exists($PNG_TEMP_DIR)) 
  40     $filename = $PNG_TEMP_DIR.'test.png'; 
  42     //processing form input 
  43     //remember to sanitize user input in real-life solution !!! 
  44     $errorCorrectionLevel = 'L'; 
  45     if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) 
  46         $errorCorrectionLevel = $_REQUEST['level'];     
  49     if (isset($_REQUEST['size'])) 
  50         $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); 
  53     if (isset($_REQUEST['data'])) {  
  55         //it's very important! 
  56         if (trim($_REQUEST['data']) == '') 
  57             die('data cannot be empty! <a href="?">back</a>'); 
  60         $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; 
  61         QRcode
::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);     
  66         echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>';     
  67         QRcode
::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2);     
  71     //display generated file 
  72     echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>';   
  75     echo '<form action="index.php" method="post"> 
  76         Data: <input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" />  
  77         ECC: <select name="level"> 
  78             <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option> 
  79             <option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option> 
  80             <option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option> 
  81             <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option> 
  83         Size: <select name="size">'; 
  86         echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>'; 
  89         <input type="submit" value="GENERATE"></form><hr/>'; 
  92     QRtools
::timeBenchmark();