0

How do I check a file exists or not in Javascript?

I know a way which is through XMLHTTP component and checking ".status" will tell is it exists or not.

Is there any other preferred way?

Thanks.

EDIT The file will be on server.

2
  • Where the file is supposed to exist? On the server-side or client-side? Commented Jul 15, 2009 at 9:11
  • Sorry I didn't mention at first. It will be on server. Commented Jul 15, 2009 at 9:16

2 Answers 2

4

Since JavaScript running in the browser does not have direct access to the file system, there is no way.

Nice article with some options that you have - Reading a file from local file system using Javascript

Sign up to request clarification or add additional context in comments.

Comments

0

there are no way to check filesystem on client via javascript. It's because of security.

I think, you can try to upload file to the server and get answer from server-side, if AJAX-technology allows to upload files.

But I hope, no. Or else you can upload all my system and security files, if I visit your site :)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.