如何显示所选文件的预览

How to show previews of selected files

本文关键字:文件 何显示 显示      更新时间:2023-09-26

如何显示所选文件的预览?我现在得到单个图像预览。如何循环函数?我已经检查过了如何循环这个函数?这个解决方案对我不起作用。请帮帮我。提前感谢……

我代码:

function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
var container = $('#mypreviewdiv');
var image = $('<img>').attr('src', e.target.result).css("width","70px").css("height","70px");
image.appendTo(container)
};
$.each(input.files,function(i) {
reader.readAsDataURL(input.files[i]);
});
}
}
我有这个html:
<div id="container">
<input type="file" onchange="readURL(this);"  id="fileToUpload" multiple /><br/>
<div id="total">
</div> <!-- end #total-->
<div id="mypreviewdiv" style="width:90%; height:250px; background: #FED8E7;"></div>
<button id="upload_btn">Start Uploading</button><br/>
<div class="progressbar" id="pb">
<div>
</div>    
</div>
<div id="log"></div>
<div id="status"></div>     
<div id="uplcomp"></div>
</div>

尝试更改

reader.readAsDataURL(input.files[i]);

reader.readAsDataURL(i);