简体   繁体   中英

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

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM