<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;
}
}
<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;
}
}
<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">
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