我创建了一个索引页面
<body>
<div>
<script src="~/Scripts/jquery-1.7.1.js"></script>
<style>
.thumb {
height: 75px;
border: 1px solid #000;
margin: 10px 5px 0 0;
}
</style>
@using (Html.BeginForm())
{
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
<input type="submit" name="Post" />
}
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<img class="thumb" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</div>
</body>
控制器
[HttpPost]
[ActionName("Index")]
public ActionResult Index_Post(FormCollection collection)
{
var tlist = collection["list"];
return View();
}
上传图片后,这就是它在 chrome 中的样子
但是通过查看源我得到低于渲染输出
<form action="/imgUpload" method="post"><input type="file" id="files" name="files[]" multiple />
如何从该 div 读取所有图像并将它们保存到磁盘?
编辑
示例脚本:http ://www.html5rocks.com/en/tutorials/file/dndfiles/
我可以在那里看到同样的问题