Last active
August 29, 2015 14:03
-
-
Save tchap/330f57cbf0de5f525561 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
<!DOCTYPE html> | |
<html> | |
<body> | |
<form> | |
<input id="fileInput" type="file"></input> | |
</form> | |
<span id="fileContent"></span> | |
<script type="text/javascript"> | |
var apiAvailable = function() { | |
return window.File && window.FileReader; | |
}; | |
document.getElementById("fileInput").addEventListener("change", function(e) { | |
if (!apiAvailable()) { | |
alert("The File API is not available, go away!"); | |
return; | |
} | |
var files = e.target.files; | |
if (files.length == 0) { | |
return; | |
} | |
var file = files[0]; | |
var reader = new FileReader(); | |
reader.onload = function() { | |
var result = reader.result; | |
document.getElementById("fileContent").innerHTML = "<pre>" + result + "</pre>"; | |
}; | |
reader.readAsBinaryString(file); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment