Guest User

Untitled

a guest
Jun 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Demo QR Code</title>
  5. </head>
  6. <body>
  7. <h1>PHP QR Code</h1>
  8. <?php
  9. //menentukan folder temporary untuk file gambar yang akan digenerate
  10. $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
  11.  
  12. //html PNG location prefix
  13. $PNG_WEB_DIR = 'temp/';
  14.  
  15. include "phpqrcode-master/qrlib.php";
  16.  
  17. //jika folder belum ada, buat folder
  18. if (!file_exists($PNG_TEMP_DIR))
  19. mkdir($PNG_TEMP_DIR);
  20.  
  21.  
  22. $filename = $PNG_TEMP_DIR.'result.png';
  23.  
  24. //memproses input form
  25. //sanitasi dulu input dari user. Penting ini supaya tidak di-hack!!!
  26. $errorCorrectionLevel = 'L';
  27. if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
  28. $errorCorrectionLevel = $_REQUEST['level'];
  29.  
  30. $matrixPointSize = 4;
  31. if (isset($_REQUEST['size']))
  32. $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
  33.  
  34.  
  35. if (isset($_REQUEST['data'])) {
  36.  
  37. //penting!
  38. if (trim($_REQUEST['data']) == '')
  39. die('data cannot be empty! <a href="?">back</a>');
  40.  
  41. // user data
  42. $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
  43. QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);
  44.  
  45. } else {
  46.  
  47. //default data
  48. echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>';
  49. QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2);
  50.  
  51. }
  52.  
  53. //menampilkan file yang sudah dihasilkan
  54. echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>';
  55.  
  56. //config form
  57. echo '<form action="" method="post">
  58. Data:&nbsp;<textarea name="data">"'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'"</textarea>&nbsp;
  59. ECC:&nbsp;<select name="level">
  60. <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option>
  61. <option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option>
  62. <option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option>
  63. <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
  64. </select>&nbsp;
  65. Size:&nbsp;<select name="size">';
  66.  
  67. for($i=1;$i<=10;$i++)
  68. echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
  69.  
  70. echo '</select>&nbsp;
  71. <input type="submit" value="GENERATE"></form><hr/>';
  72.  
  73. // benchmark
  74. QRtools::timeBenchmark();
  75.  
  76. ?>
  77. </body>
  78. </html>
Add Comment
Please, Sign In to add comment