function ReportFileStatus(filespec)
{
   var fso, s = filespec;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   if (fso.FileExists(filespec))
      s += " exists.";
   else 
      s += " doesn't exist.";
   return(s);
}

解决方案 »

  1.   

    vivianfdlpw() 的回复,我试了一下出错啊!
      

  2.   

    这个是从微软windows script host 5.6 documentation里copy的
      

  3.   

    function ReportFileStatus()
    {
    var fso, s = document.all.TextBox1.value;
    alert(s);
    fso = new ActiveXObject("Scripting.FileSystemObject");
    if (fso.FileExists(s))
    {
    alert("OK");
    }
    else 
    {
    alert("NO");
    }

    }
      

  4.   

    以下代码测试通过:
    <script>
    function ReportFileStatus()
    {
    var fso, s = document.all.TextBox1.value;
    alert(s);
    fso = new ActiveXObject("Scripting.FileSystemObject");
    if (fso.FileExists(s))
    {
    alert("OK");
    }
    else 
    {
    alert("NO");
    }

    }
    </script>
    <body>
    <input type=text name="TextBox1" value='F:\CODE\Fudan\bin\Fudan.dll' style="width:200px">
    <input type=button value='check' onclick='ReportFileStatus()'>
    </body>
      

  5.   

    有没有不用ActiveXObject控件来检查的代码啊?
      

  6.   

    xmlhttp.status == 400  //not found
      

  7.   

    xmlhttp可以测试客户端文件是否存在?
      

  8.   

    function isFileExists(fname){
      return (new ActiveXObject("Scripting.FileSystemObject")).FileExists(fname)
    }
      

  9.   

    用ActiiveXObject没用,安全权限中以上和中都不能用的!
      

  10.   

    <script  language=javascript>
    <!--function Button1_onclick() {
    try
    {
    var sFile=document.all("File1").value;
    var _http=new ActiveXObject("MSXML2.XMLHTTP");
    _http.open("Get",sFile,false);
    _http.send();
    //alert(_http.statusText);
    if(_http.status==404){alert('文件不存在!')}
    }catch(e){
    alert("OK");
    }
    }//-->
    </script>
    <INPUT id="File1" type="file" name="File1"><INPUT id="Button1" type="button" value="Button" name="Button1" onclick="return Button1_onclick()">
      

  11.   

    ssm1226(雨中人) 我试了一下你的代码,但我输入什么系统也提示“OK”,根本就判断不到文件是否存在。
      

  12.   

    将alert("OK")改成:alert(e.description)看弹出什么错误?~`
      

  13.   

    但我不会怎样判断将要上传的文件是否真的存在???
      这个用xmlhttp应该不行吧..
      

  14.   

    将alert("OK")改成:alert(e.description)看弹出什么错误?~`无论文件是否存在,系统都提示“没有权限”
      

  15.   

    刚才我看到有个判断客户端图片是否合格的例子
    也可以在这里用
    不过 FireFox 没通过
      

  16.   

    /*chaobill 受不了你了刚找到,给你,自己改 */
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Author" CONTENT="宝玉">
    <META NAME="patch" contenet="chaobill">
    </HEAD>
    <script language="javascript">
        <!--
    //检查插入是否为图片
    /*
    HTMLArea._addEvent = function(el, evname, func) {
    if (HTMLArea.is_ie) {
    el.attachEvent("on" + evname, func);
    } else {
    el.addEventListener(evname, func, true);
    }*/
    var img=null;
    function chkimg(inp)
    {
    //alert("chkimg");
    inp=document.getElementById("file1").value;
    alert(inp)
            if(img)img.removeNode(true);
            img=document.createElement("img");
    img.src="file:///"+inp;
    img.style.width=100;
    img.style.height=100;
    img.style.visibility="hidden"
    img.style.visibility="visible"
    var body=document.getElementsByTagName("body")[0];
    body.appendChild(img)
    alert(img.src); /*var is_ie=true;
    if(is_ie){
            img.attachEvent("onreadystatechange",isimg);
            img.attachEvent("onerror",notimg);
            img.src=inp;
    }else{
    }*/
    }
    function notimg()
    {
            alert("您插入的不是图片,请重新选择插入");
    }
    function isimg()
    {
    var show = document.getElementById("show")
    var show1 = document.getElementById("show1");
            show.insertAdjacentElement("BeforeEnd",img);
            show1.innerHTML = "图片大小" + img.fileSize/1024 +"K图片宽度"+ img.offsetWidth +"图片高度"+ img.offsetHeight;
    }
    function chkimg1()
    {
    alert("SDFS");
    }
    // -->
    </script>
    <BODY>
    <div id="show"></div>
    <div id="show1"></div>
    <input type="file" id="file1" name="" onpropertychange="chkimg(this.value)"/>
    <button onclick='chkimg()' >df</button>
    </BODY>
    </HTML>
      

  17.   

    <script language="JavaScript">
    <!--
    function CheckFile(s){
    var p=document.createElement('IFRAME');
    var h='file:///'+s.replace(/\\/g,'/').replace(/\:/g,'|');
    p.src=h;
    var s=(p.readyState=='complete');
    p=null;
    return s;
    }
    alert(CheckFile('c:\\boot.ini'));
    -->
    </script>
      

  18.   

    本机测试通过:只支持图片!
    <form name="form1" enctype="multipart/form-data" method="post" action="">
      <input type="file" name="file" onChange="checkme(this)">
    </form>
    <div id="checkmeimg" style="display:none;"></div>
    <script language="javascript">
     function checkme(obj){
      checkmeimg.innerHTML='<img src="'+obj.value+'" onerror=\'alert("not found")\' onload=\'alert("found")\'>';
     }
    </script>
      

  19.   

    通常只要禁止文件域的按键输入即可,如下:
    <INPUT id="File1" type="file" name="File1" onkeydown="if (event.keyCode==8) window.onerror=new Function('return false');event.returnValue=false" onpaste="return false;">