-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·193 lines (177 loc) · 4.95 KB
/
index.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="zh" class="no-js">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HASH</title>
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.2.0/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/component.css" />
<script src="js/jquery-3.3.1.min.js"></script>
<style>
.file {
text-align: center;
}
.file button {
margin: 0;
padding: 0;
border: 0 none;
width: 30%;
line-height: 60px;
color: #fff;
border-radius: 4px;
cursor: pointer;
outline: 0 none;
font-family: inherit;
/* margin-top: 5px; */
}
.file button.upload {
background-color: #0f73da;
}
.file button.remove {
background-color: #aaaaaa;
}
.file button.ensure {
background-color: #e74529;
}
.file input[type="file"] {
position: absolute;
top: -999em;
visibility: hidden;
}
.file input[type="submit"] {
position: absolute;
top: -999em;
visibility: hidden;
}
</style>
</head>
<body>
<div class="container">
<section class="content bgcolor-6">
<h1>HASH</h1>
<span class="input input--juro">
<input class="input__field input__field--juro" type="text" id="input-28" name='text' />
<label class="input__label input__label--juro" for="input-28">
<span class="input__label-content input__label-content--juro">NAME (English or Number)</span>
</label>
</span>
</section>
</div>
<div class="file">
<br>
<img src="666.png" width="250" height="250">
<p></p>
<button class="upload">上传</button>
<button class="remove">移除</button>
<button class="ensure">确认</button>
<input type="file" name='img' />
</div>
<script>
var f = document.querySelectorAll(".file")[0];
var ft = document.querySelector("input[type='text']");
var showImg = f.querySelector("img");
var defImgSrc = "666.png";
var inpFile = f.querySelector("input[type='file']");
//移除
f.querySelector(".remove").onclick = function () {
showImg.src = defImgSrc;
inpFile.value = "";
$('.file p').html("");
}
//上传
f.querySelector(".upload").onclick = function () {
f.querySelector("input[type='file']").click();
}
//调用python脚本测试
f.querySelector(".ensure").onclick = function () {
window.location.href = "http://gongbiao.cc/hash/show.php?text=" + ft.value + inpFile.files[0].name + "&name=" + ft.value;
}
inpFile.onchange = function () {
//console.dir(this.value);
var fileName = this.files[0].name;
var imgName = ft.value + fileName;
var fileExt = fileName.split(".").pop().toLowerCase();
if (fileExt != 'jpg' && fileExt != 'jpeg' ) {
alert("请上传jpg,jpeg图片");
this.value = "";
return;
}
//判断文件大小
var fileSize = 1024 * 1024 * 5;
if (this.files[0].size >= fileSize) {
alert("图片大于5M,请重新选择");
this.value = "";
return;
}
if (ft.value == '') {
alert("请输入用户名(不可有中文)后再上传");
this.value = "";
return;
}
//ajax操作
var formData = new FormData();
formData.append("text", imgName);
formData.append("file", this.files[0]);
r = $.ajax({
type: "POST",
url: "save.php",
// timeout : 100000,
processData: false,
contentType: false,
data: formData,
//同步传输
async: false,
// success:function(data){
// alert(data);
// }
})
//显示名称
$('.file p').html(imgName);
//将图片显示到空白处
//创建fileReader对象
var reader = new FileReader();
//图片编码完成
reader.onloadend = function (e) {
showImg.src = e.target.result;
}
//解析图片 成base 64位的图片 用fileReader的readAsDataURL 去读本地图片对象
reader.readAsDataURL(this.files[0]);
}
// file.forEach(myfunction);
</script>
<script src="js/classie.js"></script>
<script>
(function () {
if (!String.prototype.trim) {
(function () {
// Make sure we trim BOM and NBSP
var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
String.prototype.trim = function () {
return this.replace(rtrim, '');
};
})();
}
[].slice.call(document.querySelectorAll('input.input__field')).forEach(function (inputEl) {
// in case the input is already filled..
if (inputEl.value.trim() !== '') {
classie.add(inputEl.parentNode, 'input--filled');
}
// events:
inputEl.addEventListener('focus', onInputFocus);
inputEl.addEventListener('blur', onInputBlur);
});
function onInputFocus(ev) {
classie.add(ev.target.parentNode, 'input--filled');
}
function onInputBlur(ev) {
if (ev.target.value.trim() === '') {
classie.remove(ev.target.parentNode, 'input--filled');
}
}
})();
</script>
</body>
</html>