在我的应用程序中,我有一个包含一些字段和一个input file
字段的表单,一旦用户上传了一个,zip file
我想获取此文件中包含的文件名zip file
。
形式如下:
<input type="text" name="code" value="CodeValue">
<input type="text" name="Comment" value="commentValue">
<input type="file" name="zipFile" value="zipValue" accept="application/zip"
onchange="getzipFilesNames();" id="file-input">
<script>
function getzipFilesNames() {
}
</script>
我不需要提取文件,我只需要它们的名称。我如何使用javascript做到这一点?
我找到了使用JSUnzip库和JSInflate库的简单方法:这是示例代码:
var filesInput = document.getElementById("file-input").files[0];
var res;
var reader = new FileReader();
reader.readAsBinaryString(filesInput);
reader.onloadend = function(e){
var myZip = e.target.result;
var unzipper = new JSUnzip(myZip);
unzipper.readEntries();
var myFiles = unzipper.entries;
for(var i=0; i<myFiles.length; i++) {
var name = myFiles[i].fileName; // This is the file name
var content = JSInflate.inflate(myFiles[i].data); // this is the content of the files within the zip file.
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句