No client script to check file size before uploading [Discussion]
I am developing the web bas开发者_如何学Pythoned application which require to check size of any file before uploading it on server.
It would have been easy if there was any means by which web developer can check size of file at client side instead of checking at server side which could avoid unnecessary trip to server.
Is there any security concern for not providing the file size validation in javascript?
You can use Ajax, once you have file path in file input field, you send an ajax request to some server-side language to calculate its size and act accordingly. The other way is to use FSO (File System Object) but this will work only in IE.
In modern browsers there have been a lot of measures put in place to keep a (malicious) developer from determining anything about the user's filesystem. As a result there is little you can do in this respect in JavaScript.
There are several alternatives I can think of.
- Use the filesystem object (ActiveX) in IE (only) as mentioned by sAc.
- Write a flash applet that handles the uploading of files (like gmail does).
- Write any other type of plugin (Java, etc) or applet that would do the same as #2.
You're not going to get the information you're looking for using pure JavaScript without a roundtrip to the server.
精彩评论