Sometimes we need to find the size of a file at the time of uploading to prevent the file that is greater than a particular size. We can achieve this by handling "change" event of a input-file.
Examlpe: Suppose I want to upload a file less than 3 MB.
<input type="file" name="uploadFile" id="uploadFile" class="upload" title="Choose a file to upload">
<span id="fileName_error"></span>
<script>
$('#uploadFile').bind('change', function() {
handleUpload();
});
function handleUpload(){
if($('#uploadFile').val() !='')
{
//Get size of file
var size = $('#uploadFile')[0].files[0].size/1024/1024;
if(size > 3)
{
$('#fileName_error').text('Please upload the file less than 3MB.');
return false;
}
$('#fileName_error').text('');
return true;
}
}
</script>
Hope this will help you :)
0 Comment(s)