-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadfile.html
173 lines (148 loc) · 5.25 KB
/
uploadfile.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
h2 {
margin-bottom: 20px;
color: #333;
text-align: center;
}
form {
text-align: center;
}
label {
font-weight: bold;
display: block;
margin-bottom: 10px;
}
#fileInput {
margin-bottom: 20px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 20px;
background-color: #2e80b6;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #d0d5da;
}
.output {
margin-top: 20px;
padding: 20px;
border: 1px solid #ccc;
background-color: #f0f0f0;
border-radius: 4px;
white-space: pre-wrap;
}
#progressBarContainer {
margin-top: 20px;
display: none;
}
#progressBar {
width: 100%;
height: 20px;
background-color: #e0e0e0;
border-radius: 4px;
overflow: hidden;
}
#progressBarFill {
height: 100%;
background-color: #4caf50;
width: 0; /* 初始宽度为0 */
transition: width 0.3s ease;
}
</style>
</head>
<body>
<div class="container">
<h2>Upload a File</h2>
<form id="uploadForm" enctype="multipart/form-data">
<label for="fileInput">Choose a file:</label>
<br>
<input type="file" id="fileInput" name="file" accept=".zip" />
<br>
<button type="submit">Upload</button>
</form>
<div id="progressBarContainer">
<div id="progressBar">
<div id="progressBarFill"></div>
</div>
</div>
<div id="output" class="output"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js"></script>
<script>
document.getElementById('uploadForm').addEventListener('submit', function(event) {
event.preventDefault(); // 阻止表单的默认提交行为
var output = document.getElementById('output');
var progressBarContainer = document.getElementById('progressBarContainer');
var progressBarFill = document.getElementById('progressBarFill');
var fileInput = document.getElementById('fileInput');
var file = fileInput.files[0];
if (file) {
progressBarContainer.style.display = 'block'; // 显示进度条
var progress = 0;
var interval = setInterval(function() {
progress += 10; // 每次增加10%
progressBarFill.style.width = progress + '%'; // 更新进度条宽度
if (progress >= 100) {
clearInterval(interval); // 停止增加进度
// 上传完成后隐藏进度条
progressBarContainer.style.display = 'none';
// 上传完成后处理压缩包文件
handleZipFile(file);
}
}, 500); // 每500ms增加一次进度
} else {
// 输出没有选择文件的信息
output.textContent = 'No file selected. Please choose a file to upload.';
}
});
function handleZipFile(file) {
var output = document.getElementById('output');
var reader = new FileReader();
reader.onload = function(e) {
JSZip.loadAsync(e.target.result).then(function(zip) {
// 读取特定文件 readme.txt
return zip.file("1.txt").async("string");
}).then(function(content) {
var customMessage = 'Upload successful!!!\n';
customMessage += 'RESULTS:\n' + content;
// 输出自定义信息到页面
output.textContent = customMessage;
}).catch(function(err) {
output.textContent = 'Error reading zip file or specific file not found.';
});
};
reader.onerror = function(e) {
output.textContent = 'Error reading file';
};
reader.readAsArrayBuffer(file);
}
</script>
</body>
</html>