Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read contents of a file using javascript?

I have an input type="file" button. After I choose a file, I have to read the contents of the file using javascript. Is it possible to read/get contents of a chosen file using javascript or ajax?

like image 252
Sangam254 Avatar asked Dec 01 '22 03:12

Sangam254


1 Answers

You are all wrong in a way. It is possible. With the new File API you can read files before submitting them to the server. It is not available in all browsers yet though.

Check this example. Try to open a text file for example.

http://development.zeta-two.com/stable/file-api/file.html

Edit: Even though the question states "uploaded file" I interpret it as, "a file to be uploaded". Otherwise it doesn't make sense at all.

like image 58
Zeta Two Avatar answered Dec 04 '22 10:12

Zeta Two