Reading files from hard drive with javascript

后端 未结 3 1173
南方客
南方客 2021-01-23 20:05

My application creates .xml files and stores them on the user\'s hard drive; there is a default folder that I set in the web.xml to store the files, le

相关标签:
3条回答
  • 2021-01-23 20:09

    You cant access local filesystem using javascript. For accessing the file using javascript , you have to upload it to a server and access it using the files url.

    0 讨论(0)
  • 2021-01-23 20:12

    It's best to expose your files via HTTP and use mxUtils.load("http://yoursite/static/yourfile.xml").

    Search for static files on Apache HTTP Server HowTo. Setup Apache to serve your xml files, make sure that you can view xml file in browser and then use the same url in mxUtils.load call.

    0 讨论(0)
  • 2021-01-23 20:20

    As stated, you cannot access a file on the filesystem strictly through Javascript. You could, however, use the input file type to upload the file to your server and then read it:

    <input type="file" name="myfileinput">
    

    Then, you can access it via the $_FILES global in PHP - other languages also provide this functionality through other means. Please note, again, that there is absolutely no way to access a file that is on someone's filesystem with Javascript without their consent (i.e. using the file input type). That would be a huge security risk - imagine going to a page and having it wipe your whole D:/ drive.

    0 讨论(0)
提交回复
热议问题