简体   繁体   中英

No client script to check file size before uploading [Discussion]

I am developing the web based 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.

  1. Use the filesystem object (ActiveX) in IE (only) as mentioned by sAc.
  2. Write a flash applet that handles the uploading of files (like gmail does).
  3. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM