Last active
December 16, 2015 07:59
-
-
Save Olefine/5402438 to your computer and use it in GitHub Desktop.
Add image preview without upload an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function readURL(input, i) { | |
if (input.files && input.files[0]) { | |
var reader = new FileReader(); | |
reader.onload = function(e){ | |
var image_tag = document.createElement('img'); | |
$(image_tag) | |
.attr('src', e.target.result) | |
.width(100) | |
.height(100); | |
document.getElementById("images").appendChild(image_tag) | |
}; | |
reader.readAsDataURL(input.files[i]); | |
} | |
} | |
function setImages(input){ | |
var len = input.files.length; | |
for(i = 0; i < len; i++){ | |
readURL(input, i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment