Skip to content

Instantly share code, notes, and snippets.

@pixelmord
Created May 9, 2017 04:53
Show Gist options
  • Save pixelmord/11ec1cbb0af35b59f615fa5f710de501 to your computer and use it in GitHub Desktop.
Save pixelmord/11ec1cbb0af35b59f615fa5f710de501 to your computer and use it in GitHub Desktop.
<input id="inp" type='file'>
<p id="b64"></p>
<img id="img" height="150">
function readFile() {
if (this.files && this.files[0]) {
var FR= new FileReader();
FR.addEventListener("load", function(e) {
document.getElementById("img").src = e.target.result;
document.getElementById("b64").innerHTML = e.target.result;
});
FR.readAsDataURL( this.files[0] );
}
}
document.getElementById("inp").addEventListener("change", readFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment