如果是图片的话可以,其他文件……
反正我不知道除了图片以外的文件如何检测(用fso除外)
检测图片的:
<script>
var img=null;
function ys()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=inp.value;
}
function oe()
{
alert("cant load img");
}
function orsc()
{
if(img.readyState!="complete")return false;
alert("图片大小:"+img.offsetWidth+"X"+img.offsetHeight);
alert("图片尺寸:"+img.fileSize);
}
</script>
<input id=inp type="file">
<br>
<button onclick="ys()">Test</button>

解决方案 »

  1.   

    最简单有效的方法就是用FSO了.... 用下面的函数来探测就可以了...
    <script language="javascript">
    function FileExist(strFile)
    {
       var FSO = new ActiveXObject("Scripting.FileSystemObject");
       return FSO.FileExists(strFile);
    }
    </script> 
    传入文件全路径,返回一个布尔值.....
      

  2.   

    楼上的兄弟,我按照你的方法做了,但好象不行啊..现在附上源代码如下:
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    function check()
    {  var FSO = new ActiveXObject("Scripting.FileSystemObject");
       
       if(document.theform.title.value=="") {
    document.theform.title.focus();
         alert("请输入新闻标题!");
    return false;
        }
        if(document.theform.D.value=="") {
    document.theform.D.focus();
         alert("请输入发表日期!!");
    return false;
        }
         if(document.theform.note.value=="") {
    document.theform.note.focus();
         alert("请输入新闻内容!");
    return false;
        }
       if(document.theform.picpath.value=="")){
         
       if(NOT FSO.FileExists(document.theform.picpath.value)){
       alert("你所选的图片不存在,请重新选择!");
       return false;
       }
      }
       return true; 
    }  
       </script>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>添加新闻</title>
    </head><body>
    <form  method="post"  name="theform" action="savenews.jsp" onsubmit="return check()">
      <table width="100%"   border="1" align="center">
        <!--DWLayoutTable-->
        <tr> 
          <td width="760"><div align="center">标题: 
              <input type="text" name="title">
            </div></td>
        </tr>
        <tr> 
          <td><div align="center"> 发表日期: 
              <input type="text" name="D">
              (年/月/日)</div></td>
        </tr>
        <tr> 
          <td height="29" valign="top"> <div align="center">新闻类型: 
              <select name="type">
                <option value="1" selected>新闻</option>
              </select>
            </div></td>
        </tr>
        <tr> 
          <td height="560" valign="top"> <div align="center">内容: <font size="1"> 
              <textarea name="note" cols="100" rows="40" ></textarea>
              </font> </div></td>
        </tr>
        <tr> 
          <td height="31" valign="top"> <div align="center">选择图片(如果有就选择): 
              <input type="file" name="picpath">
              <font size="1"> </font> </div></td>
        </tr>
        <tr> 
          <td height="32" valign="top"> <div align="center"> 
              <input type="hidden" name="flag" value="0">
              <input type="hidden" name="id" value="0">
              <input type="submit" name="Submit" value="保存">
              <input type="reset" name="Submit2" value="重置">
            </div></td>
        </tr>
        <tr> 
          <td height="10"></td>
        </tr>
      </table>
    </form></body>
    </html>
      

  3.   

    用FSO肯定可以的.我这里有一段VBS写的,你看看:
    function FileIfExist(filePath)
    filePathStr=trim(filePath)
    if filePathStr="" then
    FileIfExist=false
    else
    set fso=server.createobject("SCRIPTING.FileSystemObject")
    on error resume next
    set anFile=fso.getfile(filepathStr)
    if err then
    FileIfExist=false
    else
    FileIfExist=true
    end if
    err.clear()
    fso.close()
    set fso=nothing
    end if
    end function
      

  4.   

    用FSO啊,不然检测太麻烦了。
      

  5.   

    !-_-
    难道各位都不知道客户端使用fso会有安全警告的么……
      

  6.   

    你在IE里-->"工具"-->"internet选项"-->"安全"-->"自定义级别"-->将ActiveX设为启用 . .