2

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?

4
  • 1
    No. No you cannot. You cannot read the file system in client side javascript over the internet. Commented Dec 6, 2011 at 14:10
  • This is Mozilla specific, so not an answer, but they've got a new native Javascript file management API that's pretty sweet. Commented Dec 6, 2011 at 14:11
  • please specify if it's client side(browser) or server side javascript Commented Dec 6, 2011 at 14:16
  • Reading local files in JavaScript Commented Dec 6, 2011 at 14:17

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.