教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 javascript判断文件是否存在(客户端、服务器端)

javascript判断文件是否存在(客户端、服务器端)

发布时间:2015-04-10   编辑:jiaochengji.com
分享下javascript判断文件是否存在的方法,分为客户端与服务器商两种情况,有需要的朋友参考下。

1,判断客户端文件
 

复制代码 代码示例:
var fso,s=filespec;   // filespec="C:/path/myfile.txt"
fso=new ActiveXObject("Scripting.FileSystemObject");
if(fso.FileExists(filespec))
s+=" exists.";
else
s+=" doesn't exist.";
alert(s);

2,判断服务器端(网络文件)
 

复制代码 代码示例:
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",yourFileURL,false);
xmlhttp.send();
if(xmlhttp.readyState==4){  
if(xmlhttp.status==200)s+=" exists."; //url存在  
else if(xmlhttp.status==404)s+=" doesn't exist."; //url不存在  
else s+="";//其他状态  
}
alert(s);

备注:
<input style="width:100%" type="file" name="" id="" contentEditable="false">中,可以把contentEditable设置成false限制用户只能选择文件

您可能感兴趣的文章:
js 判断客户端能否上网多种方法
javascript判断文件是否存在(客户端、服务器端)
实例详解php cookie与session会话基本用法
asp.net中Cookie同Session的关系
Asp.net中实现HtmlButton客户端控制网页提交实现
PHP 不得不提的 session 与 cookie
php在web开发中的处理过程是什么
VC写的ActiveX控件能不能被ASP.NET引用
php的cookie怎么使用
禁止客户端js缓存的方法控讨

关键词: 客户端   
[关闭]
~ ~