Skip to content

Instantly share code, notes, and snippets.

@kolipass
Last active August 31, 2017 17:06
Show Gist options
  • Save kolipass/c353e829af56f0c61d214200c719a1d2 to your computer and use it in GitHub Desktop.
Save kolipass/c353e829af56f0c61d214200c719a1d2 to your computer and use it in GitHub Desktop.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<body>
<input type="file" id="theFile" />
<image id="myimage" />
<script type="text/javascript">
document.getElementById('theFile').addEventListener('change', example);
function example(evt) {
var files = evt.target.files;
f= files[0];
//.... the user has choosen an image file
var reader = new FileReader();
reader.onload = function(evt) {
document.getElementById('myimage').src=evt.target.result;
};
reader.readAsDataURL(f);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment