Created
February 24, 2016 12:51
-
-
Save jherrlin/b0b45736a32417a0d3cc to your computer and use it in GitHub Desktop.
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
<script type="text/javascript"> | |
function loadImageFileAsURL() | |
{ | |
var filesSelected = document.getElementById("image").files; | |
var base64 = document.getElementById("base64"); | |
if (filesSelected.length > 0) | |
{ | |
var fileToLoad = filesSelected[0]; | |
var fileReader = new FileReader(); | |
fileReader.onload = function(fileLoadedEvent) | |
{ | |
var textAreaFileContents = document.getElementById | |
( | |
"textAreaFileContents" | |
); | |
textAreaFileContents.innerHTML = fileLoadedEvent.target.result; | |
base64.value = fileLoadedEvent.target.result; | |
}; | |
fileReader.readAsDataURL(fileToLoad); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment