下面这个是上传代码,比如我要将上传的文件类型设定为 JPG 要在哪里加入检测 <html> <head> <title>图片上传</title> <style> td{font-size:9pt;line-height:140%} body{font-size:9pt;line-height:140%} a:link { color: #0033CC; text-decoration: none } a:visited { color: #0033CC; text-decoration: none } a:hover { color: #000000; text-decoration: underline} </style> </head> <body topmargin="0" leftmargin="0"> <% dim upload,file,formName,formPath,iCount set upload=new upload_5xSoft ''建立上传对象 'response.write upload.Version&"<br><br>" ''显示上传类的版本 if upload.form("filepath")="" then ''得到上传目录 HtmEnd "请输入要上传至的目录!" set upload=nothing response.end else formPath=upload.form("filepath") ''在目录后加(/) if right(formPath,1)<>"/" then formPath=formPath&"/" end if iCount=0 for each formName in upload.file ''列出所有上传了的文件 set file=upload.file(formName) ''生成一个文件对象 if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据 dim fname fname = now() fname = replace(fname,"-","") fname = replace(fname," ","") fname = replace(fname,":","") fname = replace(fname,"PM","") fname = replace(fname,"AM","") fname = replace(fname,"上午","") fname = replace(fname,"下午","") fname = int(fname) + int((10-1+1)*Rnd + 1) 'fname=""&fname&"."&GetExtendName(file.FileName)&"" fname=""&fname&".gif" file.SaveAs Server.mappath(formPath&fname) ''保存文件 tmp = "http://" & request.servervariables("SERVER_NAME") & _ left(request.servervariables("SCRIPT_NAME"),len(request.servervariables("SCRIPT_NAME"))-len("/admin/upload.asp")) picurl=tmp&formPath&fname picurl = replace(picurl,"..","") end if set file=nothing next set upload=nothing 'Htmend iCount&" 个文件上传结束!" sub HtmEnd(Msg) set upload=nothing end sub function GetExtendName(FileName) dim ExtName ExtName = LCase(FileName) ExtName = right(ExtName,3) ExtName = right(ExtName,3-Instr(ExtName,".")) GetExtendName = ExtName end function if picurl<>"" then%> 请将图片地址复制到上面:<input type=text name=T1 size=50 value=<%=picurl%>> [<a href="Javascript:history.go(-1)">继续上传</a>] <%else%>请先选择你要上传的图片 [<a href="Javascript:history.go(-1)">重新上传</a>]<%end if%> </body> </html>
GetExtendName(file.FileName) 这个函数返回的就是文件的扩展名,你可以将其与允许的扩展名加以比较,例如: 代码: If GetExtendName(file.FileName) <> "jpg" And GetExtendName(file.FileName) <> "gif" Then Response.Write("不允许的文件") Response.End() End If 你可以根据你的需要来完善该代码。