How could you use HTML to open a file on the client’s machine as plaintext (i.e., a .cpp, .txt, or even a .html file)? I want to extract the plain textfile from the user’s machine into an HTML <textarea>. Just FYI, I am using hiccup, clojure, and webnoir to generate the HTML and server so those are all other options to use to help the process along.
How could you use HTML to open a file on the client’s machine as
Share
You have two main options: upload the file to your server to be served as HTML content or use HTML 5’s File API. This question also addresses a few more options (like applets, enabling drag-and-drop with the File API, etc.)
Upload the file
<input type="file" .../>on one pagePros:
Cons:
HTML 5 Solution
<input type="file" .../>Pros:
Cons:
I grabbed this code snippet from this site, which has some good examples of using the File API: