当前位置: 移动技术网 > IT编程>开发语言>Java > javascript判断文件是否存在实例代码

javascript判断文件是否存在实例代码

2017年12月08日  | 移动技术网IT编程  | 我要评论

 javascript判断文件是否存在

1. 客户端

<script language="javascript">
function fileexist()
{
  var sfso=new activexobject("scripting.filesystemobject");
  var fpath="[the path of the file]";
  if(sfso.fileexists(fpath))
  {
       alert("exist");
  }
  else
  {
    alert("doesn't exist");
    }
}
</script>

2. 服务器端

<script language="javascript">
function fileexist()
{
  var xmlhttp=new activexobject("microsoft.xmlhttp");
  xmlhttp.open("get",fileurl,false);
    xmlhttp.send();
    if(xmlhttp.readystate==4)
  { 
       if(xmlhttp.status==200) alert("exist"); 
       else if(xmlhttp.status==404) alert("doesn't exist");
       else alert("don't know"); 
    }
 }
</script>

 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网