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

Javascript determines whether the file exists (client/server side)_javascript skills

WBOY
Release: 2016-05-16 16:36:19
Original
1789 people have browsed it

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);
Copy after login

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);
Copy after login

You canSet contentEditable to false to restrict users to only select files, not just any Enter.

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