-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimag.html
47 lines (42 loc) · 1.21 KB
/
imag.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<!-- <input type="file" id="file" onchange="FileValidation(event)" >
Uploaded Image<img id="output">
</body> -->
<input type="file" id="filetag">
<img src="" id="preview">
<script>
// FileValidation = (event) => {
// var image = document.getElementById('output');
// image.src = URL.createObjectURL(event.target.files[0]);
// const fi = document.getElementById("file");
// if (fi.files.length > 0) {
// for (const i = 0; i <= fi.files.length - 1; i++) {
// const fsize = fi.files.item(i).size;
// const file = Math.round((fsize / 1024));
// }
// }
// }
var fileTag = document.getElementById("filetag"),
preview = document.getElementById("preview");
fileTag.addEventListener("change", function() {
changeImage(this);
});
function changeImage(input) {
var reader;
if (input.files && input.files[0]) {
reader = new FileReader();
reader.onload = function(e) {
preview.setAttribute('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
</body>
</html>