JavaScript/Working with files

From Wikibooks, open books for an open world
Jump to navigation Jump to search

With pure HTML4 and pure JavaScript, there's really only one thing you can do with the users files:

The server sends a Web page that includes a form something like this:[1]

<form action="/upload_handler" method="post">
  <input type="file" />

and then, the browser allows the user to select one file, and the browser uploads it -- without any JavaScript on the client being able to see any of that data or cancel the transmission or even show a progress bar.

If you want JavaScript to know anything about the file before it is transmitted (for example, to immediately cancel the transmission of a large file rather than wait an hour for the file to be transmitted, then tell the user "File too large"; or to show a progress bar), you'll have to use something other than pure JavaScript on pure HTML4.

Some popular options are:[2][3][4][5]

  • use a modern Web browser that supports the HTML5 File API.
  • use Flash (perhaps a tiny flash utility like Gmail uses to draw a little progress bar)
  • use a Java applet
  • use an ActiveX control

References[edit | edit source]