Share how to use javascript to determine whether a file exists.
1. When judging client files, you can use
var fso,s=filespec; // filespec="C:/path/myfile.txt" fso=new ActiveXObject("Scripting.FileSystemObject"); if(fso.FileExists(filespec)) s+=" exists."; else // www.jb51.net s+=" doesn't exist."; alert(s);
2. When judging the server side (network file), you can use
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);
You canSet contentEditable to false to restrict users to only select files, not just any Enter.