I use a standard <input type="file">
tag for the user to select a file, how can I use Ajax to access that file and read its contents once the user selects it?
Asked
Active
Viewed 18 times
0
-
Clarify "access". Do you want to open and read the file contents? You need to upload it, you can upload it with a javascript script *MAYBE* – Martin Jul 16 '22 at 17:52
-
yes read its content – Joseph K Jul 16 '22 at 17:53
-
Please update your question with examples of what you've tried already and why these things did not work. Also clarify exactly what result you are looking for. Read **[How to ask a good question](https://stackoverflow.com/help/how-to-ask)** – Martin Jul 16 '22 at 17:53
-
Are you talking about accessing the file before it is uploaded by the user submitting the input form, or are you asking about accessing the file once the user has given it to the server to store via the file upload HTML input mechanism? – Martin Jul 16 '22 at 17:55
-
once the user has given it to the server, is it possible before? – Joseph K Jul 16 '22 at 17:56
-
[Does reading other questions on this topic help you?](https://stackoverflow.com/questions/24658590/in-javascript-how-do-you-open-a-file-from-the-server) – Martin Jul 16 '22 at 17:57
-
yeah thanks, I think that will do – Joseph K Jul 16 '22 at 18:00
1 Answers
1
Use Change event as defined below and access the file using FileReader Object. An example can be seen from here
<input type="file" name="file" id="file" onchange="changeFile(this)" />

Nouman Ahmad
- 102
- 7