is it possible to read a file using javascript?

后端 未结 6 1358
别那么骄傲
别那么骄傲 2020-12-07 04:25

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 i

6条回答
  •  伪装坚强ぢ
    2020-12-07 04:40

    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.

提交回复
热议问题