__HTML_5读取文件API
原创
©著作权归作者所有:来自51CTO博客作者diligenceday的原创作品,请联系作者获取转载授权,否则将追究法律责任
//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>
天道酬勤