admin管理员组文章数量:1323035
I am trying to catch a file on a input[type=file]
change event :
Here is my HTML :
<input type="file" id="file-upload" name="file-upload">
Here is my JavaScript (using jQuery) :
$('#file-upload').bind("change", function(e){
var file = (e.srcElement || e.target).files[0];
console.log(e);
}
It works fully fine with images, txt, doc, docx, xlsx etc etc etc BUT NOT with zip files. When I try it with a zip file, the var file contains a type attributes empty.
Do you have an idea why and how i could get it?
EDIT 1 I use Chrome Browser, in Windows 7. My files are zipped with 7zip.
EDIT 2 here is what I get :
I am trying to catch a file on a input[type=file]
change event :
Here is my HTML :
<input type="file" id="file-upload" name="file-upload">
Here is my JavaScript (using jQuery) :
$('#file-upload').bind("change", function(e){
var file = (e.srcElement || e.target).files[0];
console.log(e);
}
It works fully fine with images, txt, doc, docx, xlsx etc etc etc BUT NOT with zip files. When I try it with a zip file, the var file contains a type attributes empty.
Do you have an idea why and how i could get it?
EDIT 1 I use Chrome Browser, in Windows 7. My files are zipped with 7zip.
EDIT 2 here is what I get :
Share Improve this question edited May 28, 2014 at 15:49 BastienSander asked May 28, 2014 at 14:20 BastienSanderBastienSander 1,8485 gold badges26 silver badges56 bronze badges 2-
What do you mean by "var file contains a type attributes empty" What attributes? Where do you use
file
in your script? What does it output? – Bergi Commented May 28, 2014 at 14:23 - 2 It works here: jsfiddle/rvd6T – enapupe Commented May 28, 2014 at 14:24
1 Answer
Reset to default 3Your code works.
I tried enapupe's fiddle and it works http://jsfiddle/rvd6T/
$('#file-upload').bind("change", function(e){
var file = (e.srcElement || e.target).files[0];
console.log(file);
console.log(e);
});
My console log
You should be be aware that the types will vary.
sometimes it would be type: "application/x-zip-pressed" or "application/zip"
You most likely should just base it on the filename instead, *.zip (ends with zip & case insensitive)
but still must check it on server side if its actually a ZIP file and unzipable
本文标签: javascriptGetting the file type of a zip file in input fileStack Overflow
版权声明:本文标题:javascript - Getting the file type of a zip file in input file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742107954a2421109.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论