Client side File Size Limit in javascript


<html>
<head>
<script>
function getSize()
{
    var myFSO = new ActiveXObject("Scripting.FileSystemObject");
    var filepath = document.upload.file.value;
    var thefile = myFSO.getFile(filepath);
    var size = thefile.size;
 
    if(size < 1048576)
    {
        alert("FIle upload");
        }
        else {
            alert("file must be select < 1 MB");
        }
        
}
</script>
</head>
<body>
<form name="upload">
<input type="file" name="file">
<input type="button" value="upload" onClick="getSize();">
</form>
</body>
</html>


9 thoughts on “Client side File Size Limit in javascript

  1. Sorry I just took the code and ran it with a file of size 22.22Mb and it does not work the function is getting called as i added an alert to it at the beginning but the other alerts did not popup

  2. Everyone on web is saying that it’s impossible to test the size of an archive ‘client-side’ (via javascript), but this simple code works great and so I could fix my pages (my provider won’t allow Uploads of more than 20 MB each. Thanks a lot!
    Stefano

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s