Skip to content

Instantly share code, notes, and snippets.

@ctosib
Created January 3, 2017 09:38
Show Gist options
  • Save ctosib/3151a184e616c8d9c80a01cf5f6c5dff to your computer and use it in GitHub Desktop.
Save ctosib/3151a184e616c8d9c80a01cf5f6c5dff to your computer and use it in GitHub Desktop.
如何利用javascript ReadFile API去讀取local的File
<html>
<head>
</head>
<body>
<input type="file" id="files" name="files" multiple />
<div id="output">
</div>
<script>
function openFile(event){
var files = event.target.files;
var reader = new FileReader();
reader.onload = function(){
var text = reader.result;
console.log(text)
document.getElementById("output").innerText=text;
};
reader.readAsText(files[0]);
}
document.getElementById("files").addEventListener("change",openFile,false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment