Skip to content Skip to sidebar Skip to footer

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-filer

Solution 1:

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.


Solution 2:

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.


Post a Comment for "Read A Local File Using Javascript"