<!--#include FILE="down_conn.asp"-->
<!--#include FILE="inc/const.asp"-->
<!--#include FILE="down_function.asp"-->
<!--#include FILE="down_upload.inc"--> 
<%
dim act,formPath
act=request("act")

Dvbbs.Stats="文件上传"

if not Dvbbs.founduser then
  	FoundErrs  "您没有<a href=login.asp target=_blank>登录</a>。"
End If

ShowErrs(Dvbbs.Stats)

%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type=text/css>
body  { margin:0px; font:normal 10px 宋体;
SCROLLBAR-FACE-COLOR: #899AE1; SCROLLBAR-HIGHLIGHT-COLOR: #799AE1; 
SCROLLBAR-SHADOW-COLOR: #599AE1; SCROLLBAR-DARKSHADOW-COLOR: #799AE1; 
SCROLLBAR-3DLIGHT-COLOR: #999AE1; SCROLLBAR-ARROW-COLOR: #FFFFFF;
SCROLLBAR-TRACK-COLOR: #AABFEC;border-collapse: collapse;
}
A{text-decoration:none;color:black}
A:hover {COLOR: #ff0000; TEXT-DECORATION: underline}
body{font-size: 9pt;}
td{font-size:9pt;}
.buttonface{  FONT-SIZE: 9pt;  HEIGHT: 20px; }
.smallInput{FONT-SIZE: 9pt;  HEIGHT: 20px; }
.b2{font-size: 7pt; font-family:"Verdana", "Arial", "宋体";}


</style>
<%
DIM j,filename1
'上传组件选择:Upload_type=参数
'参数说明:0＝无组件，1＝LyfUpload，2＝AspUpload3.0，3＝SA-FileUp 4.0，4=DvFile.Upload V1.0
dim upload_type
dim upload,file,formName,iCount,filename,fileExt
upload_type=UpFileMod

set rss=conndown.execute("select * from [showpage]")

select case upload_type
	Case 0
		Call Upload_0()
	Case 1
		Call Upload_1()
	Case 4
		formPath=Request.Form("filepath")
		if right(formPath,1)<>"/" then formPath=formPath&"/" 
		Call Upload_2()
	Case else
		response.write "本系统未支持该插件功能!"
		response.end
end select

'=====================无组件上传=======================================================
sub upload_0()
	Set Upload = New UpFile_Class						''建立上传对象
	Upload.InceptFileType = replace(rss("uptype"),"|",",")		'上传类型限制
	Upload.MaxSize = rss("upsizemax")	'限制大小
	Upload.GetDate()	'取得上传数据
 	formPath=upload.form("filepath")
 	if right(formPath,1)<>"/" then formPath=formPath&"/" 

	If Upload.Err > 0 Then
		Select Case Upload.Err
			Case 1 : Response.Write "<font size=2>请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
			Case 2 : Response.Write "<font size=2>文件大小超过了限制　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
			Case 3 : Response.Write "<font size=2>文件格式不对　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
		End Select
		Exit Sub
	Else
		iCount=0
		For Each FormName in Upload.file		''列出所有上传了的文件
			Set File = Upload.File(FormName)	''生成一个文件对象
			If File.Filesize<rss("upsizemin")Then
		 		Response.Write "<font size=2>请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
				Exit Sub
	 		End If
	 		
			FileExt	= FixName(File.FileExt)
 			If Not CheckFileExt(FileExt) Then
 				Response.Write "<font size=2>文件格式不对　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
				Exit Sub
			End If
			
			dim filename1
			filename1=UserFaceName(FileExt)
 			FileName=FormPath&filename1
 			If File.FileSize>0 Then   ''如果 FileSize > 0 说明有文件数据
				File.SaveToFile Server.mappath(FileName)   ''保存文件
				Response.Write "<script>parent.document.forms['up'].txtfilename"&act&".value='" & filename1 & "'</script>"
				if act="" then act=0
				act=act+1
  				response.write "<script>parent.document.forms['up'].ldown"&act&".options[1].selected=true;</script>"
				Response.Write "<script>parent.document.forms['up'].size1.value='" & Upload.FileSize & " K'</script>"
 				iCount=iCount+1
 			End If			
 			Set File=Nothing
		Next
	End If
	Set Upload=Nothing

Htmend iCount&" 个文件上传结束!"
end sub

'===========LyfUpload组件上传(Upload_1)=========================
Sub Upload_1()
	Dim obj,FileName,FileExt
	Dim ss
	Set obj = Server.CreateObject("LyfUpload.UploadFile")
	'大小
  obj.maxsize = rss("upsizemax")
	'类型
  obj.extname = replace(rss("uptype"),"|",",")
  
	'重命名
	formPath=obj.request("filepath")
	'在目录后加(/)
	if right(formPath,1)<>"/" then formPath=formPath&"/" 
	
	If obj.request("fname") = "" Or IsNull(obj.request("fname")) then
		Response.Write "请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
		Exit Sub
	End If
	FileExt		= Mid(obj.Request("fname"), InStrRev(obj.Request("fname"), ".")+1)
	FileExt		= FixName(FileExt)
	FileName	= UserFaceName(FileExt)
	If Not CheckFileExt(FileExt) Then
 		Response.Write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
		Exit Sub
	End If
	ss=obj.SaveFile("file1",Server.MapPath(FormPath), true,FileName)
	If ss = "3" Then
		Response.Write ("文件名重复 [ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		Response.End
	ElseIf ss = "0" Then
   	Response.Write ("文件大小超过限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		Response.End
	ElseIf ss = "1" Then
		Response.Write ("文件不是指定类型文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		Response.End
	ElseIf ss = "" Then
		Response.Write ("文件上传失败 [ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		response.end
	Else
		Response.Write "文件上传成功!" 
		Response.Write "<script>parent.document.forms['up'].txtfilename"&act&".value='" & filename & "'</script>"
		if act="" then act=0
 		act=act+1
  	response.write "<script>parent.document.forms['up'].ldown"&act&".options[1].selected=true;</script>"
		'response.end
	End if
	Set obj=nothing
End Sub

'===========DvFile-Up V1.0组件上传====================
Sub Upload_2()
	Dim Upload, FileName, FileName1, File, FileExt
	Set Upload = Server.CreateObject("DvFile.Upload")	''建立上传对象
	Upload.InceptFileType = replace(rss("uptype"),"|",",")		''上传类型限制
	Upload.MaxSize = rss("upsizemax")	''限制大小
	Upload.Install										''取得上传数据
	If Upload.Err > 0 Then
		Select Case Upload.Err
			Case 2 : Response.Write "文件大小超过了限制!"
			Case Else
			Response.Write Upload.Description
		End Select
		Response.Write "　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
		Exit Sub
	Else
		'If Upload.Count>1 Then Response.Write "上传个数超过限制" : Exit Sub
		For Each FormName in Upload.File		''列出所有上传了的文件
			Set File = Upload.File(FormName)	''生成一个文件对象
				If File.Filesize<10 Then
					Response.Write "请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
					Exit Sub
				End If
				FileExt	= FixName(File.FileExt)
 				If Not CheckFileExt(FileExt) Then
 					Response.Write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
					Exit Sub
				End If
				FileName1 = UserFaceName(FileExt)
 				FileName = FormPath & FileName1
 				If File.FileSize>0 Then   ''如果 FileSize > 0 说明有文件数据
					Upload.SaveToFile Server.Mappath(FileName),FormName		''保存文件
					Response.Write "文件上传成功!"
					Response.Write "<script>parent.document.forms['up'].txtfilename"&act&".value='" & FileName1 & "'</script>"
					if act="" then act=0
					act=act+1
  					response.write "<script>parent.document.forms['up'].ldown"&act&".options[1].selected=true;</script>"
 				End If
 			Set File=Nothing
		Next
	End If
	Set Upload=Nothing
End Sub

'==================================================================================================

sub HtmEnd(Msg)
 response.write "文件上传成功！"
 response.end
end sub

Private Function CheckFileExt(FileExt)
	Dim ForumUpload,i
	ForumUpload=replace(rss("uptype"),"|",",")
	ForumUpload=Split(ForumUpload,",")
	CheckFileExt=False
	For i=0 to UBound(ForumUpload)
		If LCase(FileExt)=Lcase(Trim(ForumUpload(i))) Then
			CheckFileExt=True
			Exit Function
		End If
	Next
End Function

'格式后缀
Function FixName(UpFileExt)
	If IsEmpty(UpFileExt) Then Exit Function
	FixName = Lcase(UpFileExt)
	FixName = Replace(FixName,Chr(0),"")
	FixName = Replace(FixName,".","")
	FixName = Replace(FixName,"asp","")
	FixName = Replace(FixName,"asa","")
	FixName = Replace(FixName,"aspx","")
	FixName = Replace(FixName,"cer","")
	FixName = Replace(FixName,"cdx","")
	FixName = Replace(FixName,"htr","")
End Function

'文件名明名
Private Function UserFaceName(FileExt)
	Dim RanNum
	Randomize
	RanNum = Int(90000*rnd)+10000
 	UserFaceName = Year(now)&Month(now)&Day(now)&Hour(now)&Minute(now)&Second(now)&RanNum&"."&FileExt
End Function

%>
