001.
<?php
002.
header(
'Content-Type: text/html; charset=UTF-8'
);
003.
004.
include
(
"connect.php"
);
005.
006.
$db
=
new
mysqli(
'localhost'
,
$dbuser
,
$dbpass
,
$dbname
);
007.
mysqli_set_charset(
$db
,
"utf8"
);
008.
009.
if
(!
$db
) {
010.
exit
(
'Connect Error ('
. mysqli_connect_errno() .
') '
011.
. mysqli_connect_error()); }
012.
013.
?>
014.
015.
<?php
016.
017.
018.
019.
020.
021.
022.
023.
024.
025.
026.
027.
028.
029.
030.
031.
032.
033.
034.
035.
036.
037.
038.
039.
error_reporting
(
error_reporting
() & ~E_NOTICE);
040.
041.
042.
$PNG_TEMP_DIR
= dirname(
__FILE__
).DIRECTORY_SEPARATOR.
'temp'
.DIRECTORY_SEPARATOR;
043.
044.
045.
$PNG_WEB_DIR
=
'temp/'
;
046.
047.
include
"qrlib.php"
;
048.
049.
050.
if
(!
file_exists
(
$PNG_TEMP_DIR
))
051.
mkdir
(
$PNG_TEMP_DIR
);
052.
053.
054.
$filename
=
$PNG_TEMP_DIR
.
'test.png'
;
055.
056.
057.
058.
$errorCorrectionLevel
=
'L'
;
059.
if
(isset(
$_REQUEST
[
'level'
]) && in_array(
$_REQUEST
[
'level'
],
array
(
'L'
,
'M'
,
'Q'
,
'H'
)))
060.
$errorCorrectionLevel
=
$_REQUEST
[
'level'
];
061.
062.
$matrixPointSize
= 4;
063.
if
(isset(
$_REQUEST
[
'size'
]))
064.
$matrixPointSize
= min(max((int)
$_REQUEST
[
'size'
], 1), 10);
065.
066.
067.
if
(isset(
$_REQUEST
[
'data'
])) {
068.
069.
070.
if
(trim(
$_REQUEST
[
'data'
]) ==
''
)
071.
die
(
'ข้อมูลที่ช่องใส่รหัส ไม่สามารถปล่อยให้ว่างได้ <br><br><a href="?">ย้อนกลับ</a>'
);
072.
073.
074.
$filename
=
$PNG_TEMP_DIR
.
'test'
.md5(
$_REQUEST
[
'data'
].
'|'
.
$errorCorrectionLevel
.
'|'
.
$matrixPointSize
).
'.png'
;
075.
QRcode::png(
$_REQUEST
[
'data'
],
$filename
,
$errorCorrectionLevel
,
$matrixPointSize
, 2);
076.
077.
}
078.
079.
080.
echo
'<img src="'
.
$PNG_WEB_DIR
.
basename
(
$filename
).
'" /><br>'
;
081.
082.
echo
'<h1 style="margin-left: 17.5px;">'
.
$_REQUEST
[
'data'
].
'</h1><br>'
;
083.
084.
085.
echo
'<form action=
"index.php"
method=
"post"
>
086.
ใส่รหัสที่ช่องนี้: <input id=
"material01"
name=
"data"
list=
"material"
autocomplete=
"off"
><datalist id=
"material"
>';
087.
088.
$queryusers1
=
"SELECT * FROM `qrcodeoptiontag` "
;
089.
090.
$db01
= mysqli_query(
$db
,
$queryusers1
);
091.
while
(
$d1
=mysqli_fetch_assoc(
$db01
)) {
092.
echo
"<option value='"
.
$d1
['shortname
']."'
/>".
$d1
[
'longname'
].
"</option>"
;
093.
}
094.
095.
echo
'</datalist><br><br> ECC: <select name=
"level"
>
096.
<option value=
"H"
'.(($errorCorrectionLevel=='
H
')?'
selected
':'
').'
>H - best</option>
097.
</select><br><br>
098.
Size: <select name=
"size"
>';
099.
100.
for
(
$i
=8;
$i
<=8;
$i
++)
101.
echo
'<option value="'
.
$i
.
'"'
.((
$matrixPointSize
==
$i
)?
' selected'
:
''
).
'>'
.
$i
.
'</option>'
;
102.
103.
echo
'</select><br><br>
104.
<input type=
"submit"
value=
"สร้าง QR Code"
></form>';