javascript判断文件是否存在实例代码
javascript判断文件是否存在
1.客户端
<scriptlanguage="javascript">
functionFileExist()
{
varsfso=newActiveXObject("Scripting.FileSystemObject");
varfPath="[Thepathofthefile]";
if(sfso.FileExists(fPath))
{
alert("Exist");
}
else
{
alert("Doesn'texist");
}
}
</script>
2.服务器端
<scriptlanguage="javascript">
functionFileExist()
{
varxmlhttp=newActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",FileURL,false);
xmlhttp.send();
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)alert("Exist");
elseif(xmlhttp.status==404)alert("Doesn'texist");
elsealert("Don'tknow");
}
}
</script>
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
