Reputation: 21
I need to delete the text in the input[file] when the uploaded file is larger than 5MB
$('input:file').change(
function(e) {
var files = e.originalEvent.target.files;
for (var i=0, len=files.length; i<len; i++){
var n = files[i].name,
s = files[i].size,
t = files[i].type;
if (s > 5242880) {
alert('Please deselect this file: "' + n + '," it\'s larger than the maximum filesize allowed. Sorry!');
}
}
});
how can I do?
http://jsfiddle.net/eHNJg/338/
thanks!
Upvotes: 1
Views: 799
Reputation: 62488
Here is the code to do it:
$('#fileUpload').live('change',
function(e) {
alert('');
var iSize = ($("#fileUpload")[0].files[0].size / 1024);
if (iSize/1024 > 5)
{
$(this).val("");
}
});
See DEMO
Upvotes: 1
Reputation: 59232
Just do this:
$('input[type=file]').val("");
after alert()
.
I've reduced the file size limit to for easy testing.
Demo:http://jsfiddle.net/eHNJg/340/
Upvotes: 0