Search code examples
javascripthtmlinput-type-file

How to read the contents of a file selected by an `<input type="file">` element?


I have a simple HTML form, where I have a field with a browse button for uploading local files.

<input type="file" id="FilePath" name="FilePath" size="18">

When fetching the uploaded file's path, it is showing as C:/fakepath/filename.xls. I came to know that it is the browser security that is not allowing to read exact file path from the local computer.

Is there any way that I can read the contents of the file?


Solution

  • You're looking for the HTML5 File API.