admin管理员组文章数量:1321070
I am using jQuery Form Plugin to upload my files via AJAX and I also want to check if size is more than 20mb on every file before I send them to server. I've discovered this HTML5 example, but I can't figure out how to put it together with my code here.
$(document).ready(function(){
$('.form-videos').ajaxForm({
success : function(data){
alert(data);
},
beforeSubmit : function(){
var fileInput = $('.form-videos :input[type=file]');
var totalFiles = $('.form-videos :input[type=file]').get(0).files.length;
for (i = 0; i < totalFiles; i++)
{
alert('what?'); // This works and prints out correctly for every file
// How do I get current file size?
}
}
});
});
I am using jQuery Form Plugin to upload my files via AJAX and I also want to check if size is more than 20mb on every file before I send them to server. I've discovered this HTML5 example, but I can't figure out how to put it together with my code here.
$(document).ready(function(){
$('.form-videos').ajaxForm({
success : function(data){
alert(data);
},
beforeSubmit : function(){
var fileInput = $('.form-videos :input[type=file]');
var totalFiles = $('.form-videos :input[type=file]').get(0).files.length;
for (i = 0; i < totalFiles; i++)
{
alert('what?'); // This works and prints out correctly for every file
// How do I get current file size?
}
}
});
});
Share
Improve this question
asked Feb 16, 2012 at 17:40
StanStan
26.5k55 gold badges168 silver badges247 bronze badges
2 Answers
Reset to default 5You should be able to;
var files = $('.form-videos :input[type=file]').get(0).files;
for (i = 0; i < files.length; i++)
{
if (files[i].size > 20971520) ...
}
See an example here.
In your example, length
is simply the number of selected files. You need to access the individual File
objects and their size
property.
本文标签: jqueryGet file size in javascript for multiple filesStack Overflow
版权声明:本文标题:jquery - Get file size in javascript for multiple files - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742091578a2420298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论