Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to read a file using javascript?

Hi all i just want to know if we can read a file using javascript like

what we do

fp=("r","path")

like that is it possible?

like image 339
Harish Avatar asked May 22 '26 00:05

Harish


2 Answers

No, that's not possible in a browser. Javascript runs in a sandboxed environment and doesn't have access to the file system. You might need to special plugins to be installed on the client browser in order to access his file system.

like image 70
Darin Dimitrov Avatar answered May 25 '26 07:05

Darin Dimitrov


Yes, this is possible, even in some browsers.

Reading a local file, from a browser

If the browser supports the new File API, you can read any file the user gives you permission to read via an input[type=file] element. Specification | Example here on StackOverflow

Read a server file, from a browser

This can be done on all major browsers using "ajax", more specifically the XMLHttpRequest object. It's made a lot easier by libraries like jQuery, Prototype, YUI, Closure, or any of several others.

On a server, workstation, etc. (not in a browser)

You'll need an environment that provides file reading, such as NodeJS.

like image 39
T.J. Crowder Avatar answered May 25 '26 08:05

T.J. Crowder