Reputation: 93
I'm trying to access a text file using javascript code, but I keep receiving a security error message. What I'm trying to do is:
var file = File('path/filename.txt');
The path is relative to the script location. I found that running from local machine could be the reason for that, so I tried to run from my local webserver but the error is still there. Does someone know why? What can I do to load this text file? If possible, considering that it is always under the script path, could it be also loaded from local disk (no web server)?
Thank you.
Upvotes: 0
Views: 146
Reputation:
Your snippet will attempt to load the file from your local file system, so can't retrieve a file from a server. You'd need to look at requestFileSystem
or FileReader
to make something like this work if the file is local.
Alternatively, you could use AJAX to retrieve the file from a server.
Upvotes: 0
Reputation: 6947
If you're trying to access a file on the server, you should do it using a server side coding language like PhP.
If you're trying to access a client file (= a file on the computer of your website visitor), it's not possible for obvious security reasons [EDIT] Thanks to Colin DeClue , I discovered this is possible using the HTML5 File API. An article explaining this is available here : http://www.html5rocks.com/en/tutorials/file/dndfiles/
Upvotes: 1