__HTML_5读取文件API

时间:2021-06-13 07:13:57

//HTML5 __FileSystemApi

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<style>
.thumb {
height: 75px;
border: 1px solid #000;
margin: 10px 5px 0 0;
}
</style> <input type="file" id="files" name="files[]" multiple />
<output id="list"></output> <script>
function handleFileSelect(evt) {
var files = evt.target.files;
for (var i = 0, f; f = files[i]; i++) { var reader = new FileReader();
reader.onload = function(e){
var span = document.createElement('span');
span.innerHTML =this.result;
document.getElementById('list').insertBefore(span, null);
} reader.readAsText(f);
    //reader.readAsArrayBuffer;
   //reader.readAsBinaryString;
   //reader.readAsDataURL
}
} document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script> </body>
</html>