tags:

views:

343

answers:

2

Hi,

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.

+4  A: 

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

Russ Cam
A: 

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 :)

Sergey Kovalenko