-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
65 lines (63 loc) · 2.31 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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Subir Archivo</title>
<style>
#progress-bar {
width: 200px;
background-color: #f3f3f3;
border: 1px solid #ddd;
margin-top: 10px;
}
#progress-bar-fill {
width: 0%;
height: 30px;
background-color: #4caf50;
text-align: center;
line-height: 30px;
color: white;
}
</style>
</head>
<body>
<input type="file" id="file-input">
<div id="file-info"></div>
<div id="progress-bar">
<div id="progress-bar-fill">0%</div>
</div>
<script>
document.getElementById('file-input').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const fileSize = file.size; // Tamaño en bytes
const fileSizeKB = (fileSize / 1024).toFixed(2); // Tamaño en KB
document.getElementById('file-info').textContent = `Tamaño del archivo: ${fileSizeKB} KB`;
const reader = new FileReader();
reader.onloadstart = function() {
console.log('Carga iniciada');
};
reader.onprogress = function(event) {
if (event.lengthComputable) {
const progress = (event.loaded / event.total) * 100;
const progressBarFill = document.getElementById('progress-bar-fill');
progressBarFill.style.width = progress + '%';
progressBarFill.textContent = progress.toFixed(2) + '%';
}
};
reader.onload = function() {
console.log('Carga completada');
const progressBarFill = document.getElementById('progress-bar-fill');
progressBarFill.style.width = '100%';
progressBarFill.textContent = '100%';
};
reader.onerror = function() {
console.error('Error al leer el archivo');
};
reader.readAsDataURL(file);
}
});
</script>
</body>
</html>