1. 程式人生 > >input標簽處理多文件上傳

input標簽處理多文件上傳

post ... spa format multipl max ase AI capture

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">

<meta name="apple-mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-status-bar-style" content="black">

<meta name="format-detection" content="telephone=no">

<title>多個文件上傳</title>

</head>

<body>

<div style="height: 100px; width: 100px; border: 1px solid red; position: relative;">

點擊上傳

<input onchange="uploadFile()" id="upload" multiple="multiple" type="file" accept="image/*;capture=camera" style="height: 100px;width: 100px;opacity: 0;position: absolute;top: 0;left: 0;" />

</div>

<script>

function uploadFile() {

var input = document.getElementById(‘upload‘);

var files = Array.prototype.slice.call(input.files);

files.forEach(function(file, i) {

var reader = new FileReader();

reader.onloadend = function(e) {

var baseFileStr = this.result.substring((13 + file.type.length),this.result.length);

console.info("輸出文件數據");

console.info(baseFileStr);

}

reader.readAsDataURL(file);

});

}

</script>

</body>

</html>

>>>輸出文件數據

>>>iVBORw0KGgoAAAANSUhEUgAAABIAAAAOCAYAAAAi2...

input標簽處理多文件上傳