mirror of
https://github.com/Kakune55/ComiPy.git
synced 2025-05-07 02:39:26 +08:00
77 lines
2.6 KiB
HTML
77 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-cn">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>文件上传</title>
|
|
<link href="static/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
#progress {
|
|
display: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container mt-5">
|
|
<h1 class="mb-3">文件上传</h1>
|
|
<form id="uploadForm">
|
|
<div class="mb-3">
|
|
<input type="file" class="form-control" id="fileInput" accept="image/*" multiple>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">上传</button>
|
|
</form>
|
|
|
|
<div class="progress mt-3" id="progress">
|
|
<div class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
|
|
</div>
|
|
|
|
<div class="alert alert-success mt-3 d-none" id="uploadSuccess" role="alert">
|
|
文件上传成功!
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('uploadForm').addEventListener('submit', function(event) {
|
|
event.preventDefault();
|
|
const fileInput = document.getElementById('fileInput');
|
|
const files = fileInput.files;
|
|
|
|
if (files.length === 0) {
|
|
alert('请选择要上传的文件!');
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
for (let i = 0; i < files.length; i++) {
|
|
formData.append('files[]', files[i]);
|
|
}
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/upload', true);
|
|
|
|
xhr.upload.onprogress = function(e) {
|
|
const percent = (e.loaded / e.total) * 100;
|
|
document.querySelector('.progress-bar').style.width = percent + '%';
|
|
document.querySelector('.progress-bar').setAttribute('aria-valuenow', percent);
|
|
};
|
|
|
|
xhr.onload = function() {
|
|
if (xhr.status === 200) {
|
|
document.getElementById('progress').style.display = 'none';
|
|
document.getElementById('uploadSuccess').classList.remove('d-none');
|
|
} else {
|
|
alert('上传失败,请重试!');
|
|
}
|
|
};
|
|
|
|
xhr.onerror = function() {
|
|
alert('上传失败,请重试!');
|
|
};
|
|
|
|
document.getElementById('progress').style.display = 'block';
|
|
xhr.send(formData);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|