Guest User

Untitled

a guest
Mar 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. //set it to writable location, a place for temp generated PNG files
  2. $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
  3.  
  4. //html PNG location prefix
  5. $PNG_WEB_DIR = 'temp/';
  6. include "qrlib.php";
  7.  
  8.  
  9. //ofcourse we need rights to create temp dir
  10. if (!file_exists($PNG_TEMP_DIR))
  11. mkdir($PNG_TEMP_DIR);
  12.  
  13.  
  14. $filename = $PNG_TEMP_DIR.'test.png';
  15.  
  16. //processing form input
  17. //remember to sanitize user input in real-life solution !!!
  18. $errorCorrectionLevel = 'L';
  19. if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
  20. $errorCorrectionLevel = $_REQUEST['level'];
  21. $matrixPointSize = 4;
  22. if (isset($_REQUEST['size']))
  23. $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
  24. if (isset($_REQUEST['data'])) {
  25.  
  26. //it's very important!
  27. if (trim($_REQUEST['data']) == '')
  28. die('data cannot be empty! <a href="?">back</a>');
  29.  
  30. // user data
  31. $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
  32. QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);
  33.  
  34. } else {
  35.  
  36. //default data
  37.  
  38. QRcode::png(' QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2);
  39.  
  40. }
  41.  
  42. //display generated file
  43.  
  44.  
  45. //config form
  46. echo '<form action="index.php" method="post">
  47.  
  48. Link:&nbsp;<input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'введите ссылку на сайт').'" />&nbsp;
  49. ECC:&nbsp;<select name="level">
  50. <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option>
  51. <option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option>
  52. <option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option>
  53. <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
  54. </select>&nbsp;
  55. Size:&nbsp;<select name="size">';
  56.  
  57. for($i=1;$i<=10;$i++)
  58. echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
  59. echo '</select>&nbsp;
  60. <input type="submit" value="Генерировать"></form><hr/>';
  61.  
  62. /* benchmark
  63. QRtools::timeBenchmark(); */ `
Add Comment
Please, Sign In to add comment