Home  >  Article  >  Web Front-end  >  Use javascript to determine whether a file exists_javascript skills

Use javascript to determine whether a file exists_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:06:081372browse

When judging the client file, you can use

to copy the code The code is as follows:

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);

When judging the server side (network file), you can use
Copy code The code is as follows:

var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",yourFileURL,false);
xmlhttp.send();
if(xmlhttp.readyState==4){
if(xmlhttp.status==200) s =" exists."; //url exists
else if(xmlhttp.status==404)s =" doesn't exist."; //url does not exist
else s ="";// Other statuses
}
alert(s);

canSet contentEditable to false to restrict users to only select files, not to type in.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn