Javascript checks whether a file exists (Client/Server) and javascript Server

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.