How can you check the file size from JavaScript in a form with an input type of file?

Jayesh Nazre

Well the answer is very simple, you cannot.

The browser security does not allow the scripts (Javascript/VBScript) or even applets and ActiveX Controls to read files from the local hard disk. You can only read files if your code is signed by some Certificate Authority (CA). Now the input type "FILE" also does not have the permission to read files. We cannot do anything about that since thats what HTML says. So since it cannot read files, it cannot find the size of the file with which the input tag is associated. Since it cannot find the file size, there is no function exposed by JavaScript/VBScript to return the file size. But if you need to find the file size, say in order to restrict the size of the file uploaded to your web-server. Then you can do so by counting the file contents on the server-side, once the user submits it to the server. Thats what many of the free e-mail providers like www.hotmail.com do.