加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 教程 > 正文

借助javascript判断文件是否存在

发布时间:2023-09-07 14:20:33 所属栏目:教程 来源:
导读:判断客户端文件时,可以用

代码如下:

var fso,s=filespec; // filespec="C:/path/myfile.txt"

fso=new ActiveXObject("Scripting.FileSystemObject");

if(fso.FileExists(filespec))

s+=" exi
判断客户端文件时,可以用
 
代码如下:
 
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);
 
判断服务器端(网络文件)时,可以用
 
代码如下:
 
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限制用户只能选择文件,而不能随便输入.
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章