<input type="file" id="testfile" onchange="checkFile(this.value.match(/\.([^\.]+)(\?|$)/)[1])">
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkFile(strtype)
{
if (strtype=="jpg"||strtype=="gif"||strtype=="bmp")
return true;
  else{
alert("这种文件类型不允许上传!\r\n只允许上传这几种文件:jpg、gif、bmp\r\n请选择别的文件并重新上传。");
document.all.testfile.focus();
return false;
  }
}

解决方案 »

  1.   

    js判断是不够的,服务段还要再判断
    <input type="file" id="testfile" onpropertychange="vbscript:hzm=right(testfile.value,3):if hzm<>'jpg' or hzm<>'gif' or hzm<>'bmp' then msgbox('不准上传') end if">
      

  2.   

    set upload=new upload_5xSoft
    set file=upload.file("file1")
    formPath=session("picpath")
    if file.filesize>100 then
    fileExt=lcase(right(file.filename,3))
    if fileExt<>"jpg" and fileExt<>"gif" and fileExt<>"bmp"then
    Response.Write"对不起,只能上传 jpg,gif和bmp图像!"
    end if
    end if
    取它的最后三位,也就是扩展名,看是不是jpg  gif  bmp?http://expert.csdn.net/Expert/topic/2540/2540173.xml?temp=.4262812