我是靠谱客的博主 忐忑乌龟,这篇文章主要介绍javascript判断文件是否存在,现在分享给大家,希望可以做个参考。

判断客户端文件时,可以用
contractedblock.gif expandedblockstart.gif Code
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();
expandedblockstart.gifcontractedblock.gif
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限制用户只能选择文件,而不能随便输入.

转载于:https://www.cnblogs.com/wudingfeng/archive/2008/10/23/1317597.html

最后

以上就是忐忑乌龟最近收集整理的关于javascript判断文件是否存在的全部内容,更多相关javascript判断文件是否存在内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(107)

评论列表共有 0 条评论

立即
投稿
返回
顶部