Javascript checks whether a file exists (Client/Server) and javascript Server
Share the javascript code to determine whether a file exists.
1. 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.nets+=" doesn't exist.";alert(s);
2. 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. "; // The url contains else if (xmlhttp. status = 404) s + = "doesn't exist. "; // The url does not exist in else s + =" "; // other statuses} // www. yuju100.comalert (s );
You can <input style = "width: 100%" type = "file" name = "" id = "" contentEditable = "false"> set contentEditable to false to restrict users from selecting files only, you cannot enter it at will.
Javascript checks whether folders exist
Oh! As far as I know, I should not be able to directly obtain the server information. To call it, you can write a method to call the server method using the ajax method, and then judge the server method and return a client.
In js, how does one determine whether a txt file exists under the project release path of the server?
I think you need to understand the language features. Javascript is short for javascript. It is a client language, that is, running on the client computer, not on the server. Therefore, you cannot determine what is on the server's Elastic Block Storage.
You should look for the server language to judge, such as php and asp. Asp can be determined by using the fso component. But let's forget about js.