-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.php
118 lines (118 loc) · 3.32 KB
/
home.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
$html = '';
$mode = 'encode';
if(!empty($_GET['mode']) && $_GET['mode']=='decode'){
$mode = 'decode';
}
$html.= '<p class="navs">';
foreach(['encode','decode'] as $k){
if($k==$mode){
$html.= '<a href="?mode='.$k.'"><b>'.$k.'</b></a> ';
}
else{
$html.= '<a href="?mode='.$k.'">'.$k.'</a> ';
}
}
$html.= '</p>'.PHP_EOL;
if($mode=='encode'){
if(!empty($_POST['action']) && $_POST['action']=='encode'){
$d = [];
if(!empty($_FILES['vault'])){
$s = $_FILES['vault'];
if(empty($s['error'])){
$d['name'] = $s['name'];
if(empty($d['name'])){
$d['name'] = 'vault.rar';
}
$d['data'] = file_get_contents($s['tmp_name']);
if(!empty($d['data'])){
$d['data'] = base64_encode($d['data']);
}
else{
$d = [];
}
}
}
if(empty($d)){
$html.= 'file encode fail, <a href="?action=encode">click here</a> try again.';
}
else{
$html.= '<p>base64_decode the text, then save the binary data as '.$d['name'].'<br>'.PHP_EOL;
$html.= 'Sample script at https://github.com/tianpu/qrcode<br>'.PHP_EOL;
$html.= '</p>'.PHP_EOL;
if(strlen($d['data'])>2331){
$html.= 'File size ('.strlen($d['data']).'B) exceed (CorrectLevel: M-2331, H-1273)'.PHP_EOL;
}
else{
$html.= '<script src="./img/easy.qrcode.min.js"></script>'.PHP_EOL;
$html.= '<div id="qrcode"></div>'.PHP_EOL;
$html.= '<script type="text/javascript">
var options = {
text:"'.$d['data'].'",
width:512,
height:512,
correctLevel:QRCode.CorrectLevel.'.(strlen($d['data'])>1273?'M':'H').'
};
new QRCode(document.getElementById("qrcode"),options);
</script>'.PHP_EOL;
}
}
}
else{
$html.= '<form method="post" enctype="multipart/form-data">'.PHP_EOL;
$html.= '<input type="hidden" name="action" value="encode">'.PHP_EOL;
$html.= '<p>Upload the file for print</p>'.PHP_EOL;
$html.= '<p><input type="file" name="vault"></p>'.PHP_EOL;
$html.= '<p><input type="submit" value="Submit"></p>'.PHP_EOL;
$html.= '</form>'.PHP_EOL;
}
}
else{
if(!empty($_POST['action']) && $_POST['action']=='decode'){
$d = [];
if(!empty($_POST['data'])){
if(!empty($_POST['name'])){
$d['name'] = $_POST['name'];
}
else{
$d['name'] = 'vault.rar';
}
$d['data'] = base64_decode($_POST['data']);
if(empty($d['data'])){
$d = [];
}
}
if(empty($d)){
$html.= 'file decode fail, <a href="?action=decode">click here</a> try again.';
}
else{
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename="'.rawurlencode($d['name']).'"');
echo $d['data'];
exit();
}
}
else{
$html.= '<form method="post">'.PHP_EOL;
$html.= '<input type="hidden" name="action" value="decode">'.PHP_EOL;
$html.= '<p>Input encoded text to decode</p>'.PHP_EOL;
$html.= '<p>File: <br><input type="text" name="name" value="vault.rar"></p>'.PHP_EOL;
$html.= '<p>Data: <br><textarea name="data" rows="13" cols="76"></textarea></p>'.PHP_EOL;
$html.= '<p><input type="submit" value="Submit"></p>'.PHP_EOL;
$html.= '</form>'.PHP_EOL;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vault</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style>@media print{.navs{display:none;}}span,pre{font-size:17px;font-family:monospace;}</style>
</head>
<body>
<?php echo $html; ?>
</body>
</html>