1function previewImages() {
2
3 var preview = document.querySelector('#preview');
4
5 if (this.files) {
6 [].forEach.call(this.files, readAndPreview);
7 }
8
9 function readAndPreview(file) {
10
11 // Make sure `file.name` matches our extensions criteria
12 if (!/\.(jpe?g|png|gif)$/i.test(file.name)) {
13 return alert(file.name + " is not an image");
14 } // else...
15
16 var reader = new FileReader();
17
18 reader.addEventListener("load", function() {
19 var image = new Image();
20 image.height = 100;
21 image.title = file.name;
22 image.src = this.result;
23 preview.appendChild(image);
24 });
25
26 reader.readAsDataURL(file);
27
28 }
29
30}
31
32document.querySelector('#file-input').addEventListener("change", previewImages);