如何在Javascript中检查文件是否存在?

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


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

如何在Javascript中检查文件是否存在?

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

我知道一种方法是通过XMLHTTP组件并检查“.status”将告诉它是否存在。

Is there any other preferred way?

还有其他首选方式吗?

Thanks.

EDIT The file will be on server.

编辑该文件将在服务器上。

2 个解决方案

#1


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

由于在浏览器中运行的JavaScript无法直接访问文件系统,因此无法实现。

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

有一些选项的好文章 - 使用Javascript从本地文件系统读取文件

#2


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

没有办法通过javascript检查客户端上的文件系统。这是因为安全。

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

我想,如果AJAX技术允许上传文件,你可以尝试将文件上传到服务器并从服务器端获得答案。

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

但我希望,不。或者,如果我访问您的网站,您可以上传我的所有系统和安全文件:)


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/07/15/94e4d65ccd33304cd458edd6ac1cce4.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号