0

I am trying to display files from the local directory using javascript. Is this possible? As earlier i used the files which were inside the project using this format : Url : './files/'. Worked pretty well with javascript. Now i want to access files from outside the project eg. Url : "d:/" But javascript has some restrictions on that. How can i load files from d: drive using javascript?

$(document).ready(function(){
URL = 'd:/content/abc.pdf'; /// ??????
});
5
  • your question is not that clear though. if you mean to access the filesystem of the client -> no chance. Jan 22, 2013 at 7:54
  • Yes. but there might be some alternate solutions? Jan 22, 2013 at 7:55
  • yes, if the client uploads the needed file. thats about the only chance you have Jan 22, 2013 at 7:56
  • He does. I am saving that in d: directory and then trying to access it using javascript! Jan 22, 2013 at 7:57
  • then you need to save it into an directory where the document is accessible by your webserver, and you can read it through yourserver/document.pdf Jan 22, 2013 at 8:03

2 Answers 2

4

No, this is not possible. When running in the context of a web page, Javascript cannot read files which are not available on the web.

1
  • Good to know that. Will have to find some alternate solution then! Jan 22, 2013 at 7:55
0

You can't load files from local computer with JavaScript. Otherwise any website would be able to steal info from user. The only way is to ask a user to upload a file (maybe with ajax) and take it from your server than.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.