user494461
user494461

Reputation:

Read a local file using javascript

How do I get the contents of a local file, say:

/home/user/Wired/uploads/1.csv

in a variable x in javascript?

Can I use the filereader http://www.w3.org/TR/file-upload/#dfn-filereader? If yes, then how?

Upvotes: 2

Views: 1137

Answers (2)

dev4life
dev4life

Reputation: 11394

Reading client files in javascript is possible indeed with the new File API available in modern browsers (I dont know if IE supports this now). Check this site and its code: http://www.readfileonline.com/ it allows you to read files using the browser only.

Upvotes: 0

Chuck Callebs
Chuck Callebs

Reputation: 16441

You can't do this with strict javascript, but you can use the web server as an intermediate between the user and the browser. Have the user upload the file asynchronously (using AJAX). The web server could then return the plain-text value back to the AJAX call. The contents would then be free to use as you see fit.

This is likely your only option without employing Flash/Silverlight/Java.

Upvotes: 1

Related Questions