In my project, I use ajaxSubmit to upload file.
The file size shoulde be limited. So before sending the file, I want to check the size of uploaded file immediately.
When I click file button, alert("test")
works successfully. But alert(ufile.size)
works fail.
I have tried $('#fId').files[0]
and $('#fulId').files[0]
, but they both works fail.
Here is my js code:
$(function () {
$("#fulId").wrap("<form id='fId' action='action.php' method='post' enctype='multipart/form-data'></form>");
$("#fulId").change(function(){
alert("test");
$("#fId").ajaxSubmit({
dataType:'json',
beforeSend: function(){
//var ufile=$('#fId').files[0];
var ufile=$('#fulId').files[0];
alert(ufile.size);
},
uploadProgress: function(){},
success: function(){},
error:function(){}
});
});
Here is html code:
<div class="attFile">
<input type="file" id="fulId" name="mypic">
</div>