I am writing a very simple Elearning application for my virtual class. I wander if there may be a way using Javascript that works on the background to read the content of a file located on the user's computer and send its content to my server. Any one knows an open source code of Javascript doing this ? I think that this can be done using XMLHttpRequest, i.e. AJAX, but I could not graps my way through. Any help
-
2https://www.google.com/search?q=javascript+read+local+file and https://www.google.com/search?q=javascript+send+data+to+server. – Waleed Khan Feb 11 '13 at 13:47
-
Accessing local files is not allowed by design. See: http://stackoverflow.com/questions/371875/local-file-access-with-javascript – Patrik Feb 11 '13 at 13:48
3 Answers
You can't gain access to a local file in browser because you are in sandbox, but there are some File API for Html 5 that you can programmatically select them and access their data just have a look at the following link
Web applications should have the ability to manipulate as wide as possible a range of user input, including files that a user may wish to upload to a remote server or manipulate inside a rich web application. This specification defines the basic representations for files, lists of files, errors raised by access to files, and programmatic ways to read files. Additionally, this specification also defines an interface that represents "raw data" which can be asynchronously processed on the main thread of conforming user agents. The interfaces and API defined in this specification can be used with other interfaces and APIs exposed to the web platform.
Unfortunately there is no way to give JavaScript any access to the user's local files. There is a very serious security issue with that.
There is however API for that on IE browsers (Which give nice big warning when you attempt to access the files)
I recommend to ask from the user to upload his own file (using <input type="file" />
) and upload it to the server.

- 1,298
- 1
- 13
- 26
HTML5 specifications specify an API to access the local filesystem. It is supported in the latest versions of Chrome. See here for details http://net.tutsplus.com/tutorials/html-css-techniques/toying-with-the-html5-filesystem-api/.
If the environment is controlled (i.e in a classroom or intranet) you can build your application using this API.

- 1,484
- 10
- 14