That old chestnut - input type = file; check file size
Hi all - this is driving me crazy but I can't find a solution. I posted a while back that I had a file input in a form that I wanted to test the file to ensure it is not over a specified file size before submission so that the form data could be submitted and emailed.
I got everything working except on FF.
Now with plenty of head banging I managed to get it to work on all browsers and FF. Great; but it stopped working on IE. Brilliant! :mad: Why can't W3C enforce a single code base which everyone else just puts their eye candy on???
Any way - I've tried several solutions and I feel so close but so far - can any one help??
Code:
<div class="fileUploadEntry">
<input type="file" id="attachment1" name="attachment[]" onchange="attachmentsGoodToGo.value = findSize(this, 5242880, 1)" />
</div>
function findSize(fileInput, maxFileSize, id) {
//limit is set to 5242880 (5mb) in bytes
//simple detect IE version script
var ver = getInternetExplorerVersion();
if(ver > -1)
{
//for IE
var exceeded = false;
var idNumber = id;
alert("id = "+id);
var elementID = "attachment"+idNumber;
var oas = new ActiveXObject("Scripting.FileSystemObject");
//the above line no longer works because of IE security.
//cannot find a jQuery solution to this
var d = document.send.elementID.value;
var e = oas.getFile(d);
var f = e.size;
alert("theFile = " + d);
alert("theFile value = " + e);
alert("fileSize = " + f);
if(f > maxFileSize)
{
var exceeded = true;
//this file is greater than 5mb - warn the user
alert("This file exceeds the 5Mb limit - please click Choose File and reselect or compress the file.");
}
}
else {
//for everyone else
var exceeded = false, bytes;
if(fileInput.files && ( bytes = fileInput.files[0].size) > maxFileSize)
{
exceeded = true;
alert("This file exceeds the 5Mb limit - please click Choose File and reselect or compress the file.");
}
}
return exceeded ? 0 : 1;
}
Any pointers would be amazing!
cheers
frank