Javascript判断文件是否存在(客户端/服务器端)
作者:bea
分享下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,判断服务器端(网
分享下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+="";//其他状态
} // www.yuju100.com
alert(s);
可以<input style="width:100%" type="file" name="" id="" contentEditable="false" >把contentEditable设置成false限制用户只能选择文件,而不能随便输入.
有用 | 无用
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+="";//其他状态
} // www.yuju100.com
alert(s);
可以<input style="width:100%" type="file" name="" id="" contentEditable="false" >把contentEditable设置成false限制用户只能选择文件,而不能随便输入.
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JS应用正则表达式转换大小写示例
- 使用不同的方法结合/合并两个JS数组
- js实现按Ctrl+Enter发送效果
- javascript搜索框点击文字消失失焦时文本出现
- 输入框过滤非数字的js代码
- 小结Node.js中非阻塞IO和事件循环
- JavaScript将取代AppleScript?
- Javascript MVC框架Backbone.js详解
- JS回调函数的应用简单实例
- js实现在同一窗口浏览图片
- js实现获取焦点后光标在字符串后
- 在JavaScript中构建ArrayList示例代码
- 取得元素的左和上偏移量的方法
- JS实现OCX控件的事件响应示例
- javascript快速排序算法详解
- js生成的验证码的实现与技术分析
- Node.js中使用Log.io在浏览器中实时监控日志(等同tail -f命令)
- nodejs命令行参数处理模块commander使用实例
- node.js中使用q.js实现api的promise化