Skip to content

Instantly share code, notes, and snippets.

@lmatt-bit
Created October 23, 2014 08:05
Show Gist options
  • Select an option

  • Save lmatt-bit/9d969885241b72937865 to your computer and use it in GitHub Desktop.

Select an option

Save lmatt-bit/9d969885241b72937865 to your computer and use it in GitHub Desktop.
Load file by using html5
<input type="file" id="inputFile" />
<textarea id="output"></textarea>
<script>
function readFile(evt) {
var fs = evt.target.files;
if(fs.length > 0) {
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById('output').innerText = reader.result;
}
reader.readAsText(fs[0]);
}
}
document.getElementById('inputFile').addEventListener('change', readFile, false);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment