Using javascript check uploaded file size, which is uploaded by a file upload control
I don’t want to post this article as this javascript is using ActiveX object and nowadays in latest browsers it will ask for user permission to access ActiveX object. Sometimes it may happen that browser does not support ActiveX object or it is disabled, at that time this code is of no use.
This code is for those people who are using ActiveX object and knows that browser will defiantly support the below script. May be it is useful to someone like me.
<script language=”javascript” type=”text/javascript”>
var objFSO ;
try
{
objFSO = new ActiveXObject(“Scripting.FileSystemObject”);
}
catch(err)
{
alert(err.message);
alert(err.number);
}
function CheckExtention(el) // pass Upload File object’s ClientID here
{
var myel= document.getElementById(el);
var file;
var path = myel.value;
//alert(path);
file = objFSO.getFile(path);
var size;
size = file.size ; // This size will be in Bytes
// We are converting it to KB as below
alert(‘File Size is : ‘ + file.size /1024 +‘ KB’);
}
</script>
November 4, 2008 at 5:39 am
what about firefox ie it will not work in firefox,safari,opera….
February 2, 2009 at 3:41 pm
I want to know about the uploading file and getting the particular file extension.
July 6, 2009 at 3:57 pm
When i run this script I’ve got a err no -2146827859 ” Does someone knew why ?
July 18, 2009 at 11:40 pm
I´m looking for the standard for all navegators
October 16, 2009 at 8:34 am
this script does not work in safari, firefox, and others, except IE… damn it.!
October 26, 2009 at 8:56 pm
if you want it with firefox it’s very simply:
fileupload = document.getElementById(‘myfile’);
if(fileupload.files)
{
var size = fileupload.files.item(0).fileSize;
}