Shai Rosenfeld wrote:
>>> For IE:
>>>
>>> function getFileSize(file) {
>>>     var oas = new ActiveXObject("Scripting.FileSystemObject");
>>>     var e = oas.getFile(file);
>>>     var f = e.size;
>>>     return f;
>>> }
>>>       
>
> ... as of uploading:
>
> how do i use this function? i want to check out the file size before 
> allowing the user to upload a file or not (essentially, i should be able 
> to limit file size uploads from lighttpd [which is what i am running] 
> but i couldn't seem to find any  doc on how to do it) so i'm thinking of 
> sending an ajax request to see what the file size of the upload is, and 
> then pass the upload, if it is the right size.
>
> the script above seems quite handy for this purpose (btw, this works 
> only for IE?)
> but i don't know what needs to go into the 'file' parameter ... i tried 
> supplying a path to the file on my system, for a check 
> "getFileSize('/home/shai/test.size') " but that didn't work .. what 
> parameter am i supposed to supply to the function?
>
> tia...
>
> shai
>
>   
Example:

<html>
<head>
<script type="text/javascript">
function getFileSize() {
    var max_allowed_size = 15; // for example :)
    var filesize = null;
    var input_file = document.getElementById("input_file").value;
    var browserName=navigator.appName;
    if (browserName=="Microsoft Internet Explorer"){
        var oas = new ActiveXObject("Scripting.FileSystemObject");
        var e = oas.getFile(input_file);
        filesize = e.size;
    }else{ 

	netscape.security.PrivilegeManager.enablePrivilege('*Universal**FileAccess*');
	var file = new java.io.File(filename);	
	// Get the number of bytes in the file
	filesize = file.length();

    }
    if(filesize > max_allowed_size){
       return false;
    }
    return true;
}
</script>
</head>
<body>
<form onsubmit="getFileSize()">
<input type="file" value="Upload file" id="input_file">
</form>
</body>
</html>