Skip to content

Instantly share code, notes, and snippets.

@Olefine
Last active December 16, 2015 07:59
Show Gist options
  • Save Olefine/5402438 to your computer and use it in GitHub Desktop.
Save Olefine/5402438 to your computer and use it in GitHub Desktop.
Add image preview without upload an image
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