Home > Web Front-end > JS Tutorial > body text

Use javascript to determine whether a file exists_javascript skills

WBOY
Release: 2016-05-16 17:06:08
Original
1374 people have browsed it

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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template