示例工程 27-file-upload
27-file-upload/demo-02-multiple/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>多文件上传演示</title>
<style>
body { margin: 0; padding: 32px; background: #f8fafc; color: #0f172a; font-family: system-ui, sans-serif; line-height: 1.7; }
.box { max-width: 720px; margin-bottom: 16px; padding: 18px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; }
h1 { margin: 0 0 16px; font-size: 28px; }
h2 { margin: 0 0 8px; font-size: 17px; }
p { margin: 0 0 10px; color: #334155; }
label { display: block; margin: 6px 0 4px; font-size: 14px; }
input[type="file"] { width: 100%; max-width: 360px; padding: 6px; border: 1px dashed #94a3b8; border-radius: 6px; background: #f8fafc; font: inherit; }
.help { color: #64748b; font-size: 13px; }
button { margin-top: 8px; padding: 7px 14px; border: 1px solid #2563eb; border-radius: 6px; background: #2563eb; color: #fff; font: inherit; }
code { padding: 1px 5px; border-radius: 4px; background: #f1f5f9; font-family: ui-monospace, monospace; }
</style>
</head>
<body>
<h1>多文件上传</h1>
<div class="box">
<h2>材料上传</h2>
<form action="preview.html" method="post" enctype="multipart/form-data">
<label for="docs">选择文件</label>
<input id="docs" name="docs" type="file" accept=".pdf,.txt" multiple aria-describedby="docs-help" />
<p class="help" id="docs-help">PDF 或 TXT,单个不超过 10 MB,最多 5 个。</p>
<button type="submit">上传</button>
</form>
</div>
<div class="box">
<h2>多选与安全</h2>
<p><code>multiple</code> 允许一次选多个文件,服务端会收到多个同名文件。</p>
<p>数量、大小、类型都要在服务端再校验。</p>
<p>文件名不可信,服务端要重命名并限制路径。</p>
</div>
</body>
</html>