<!--#include FILE="down_conn.asp"-->
<!--#include FILE="inc/const.asp"-->
<!--#include FILE="down_upload.inc"-->
<!--#include FILE="down_function.asp"-->
<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>
<%

Dvbbs.Stats="软件图片上传"


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

ShowErrs(Dvbbs.Stats)

%>
<html>
<head>
<title>软件图片上传</title>
</head>
<body>

<%

'上传方法，0＝无组件，1＝lyfupload，2＝aspupload，3＝chinaaspupload
dim upload_type,j
dim upload,file,formName,formPath,iCount,filename,fileExt

upload_type=UpPicMod

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

'上传组件选取
Select Case Upload_type
	Case 0
		Call Upload_0()
	Case 1
		Call Upload_1()
	Case 2
		formPath=Request.Form("filepath")
		if right(formPath,1)<>"/" then formPath=formPath&"/" 
		Call Upload_2()
	Case 3
		formPath=Request.Form("filepath")
		if right(formPath,1)<>"/" then formPath=formPath&"/" 
		Call Upload_3()
	Case 4
		formPath=Request.Form("filepath")
		if right(formPath,1)<>"/" then formPath=formPath&"/" 
		Call Upload_4()
	Case Else
		Response.Write "本系统未支持该插件功能"
		Response.End
End Select


'===========无组件上传(Upload_0)====================
Sub Upload_0()
	Set Upload = New UpFile_Class						''建立上传对象
	Upload.InceptFileType = replace(rss("uppictype"),"|",",")		'上传类型限制
	Upload.MaxSize = rss("uppicsizemax")	'限制大小
	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 "请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
			Case 2 : Response.Write "图片大小超过限制　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
			Case 3 : Response.Write "所上传类型不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
		End Select
		Exit Sub
	Else
		 For Each FormName in Upload.file		''列出所有上传了的文件
			 Set File = Upload.File(FormName)	''生成一个文件对象
			 If File.Filesize<rss("uppicsizemin") Then
		 		Response.Write "请先选择你要上传的图片　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
				Exit Sub
	 		End If
			FileExt	= FixName(File.FileExt)
 			If Not ( CheckFileExt(FileExt) and CheckFileType(File.FileType) ) Then
 				Response.Write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
				Exit Sub
			End If
 			FileName=FormPath&UserFaceName(FileExt)
 			If File.FileSize>0 Then   ''如果 FileSize > 0 说明有文件数据
				File.SaveToFile Server.mappath(FileName)   ''保存文件
			  response.write "<script>parent.document.forms['up'].pic.value='"&filename&"'</script>"
  			iCount=iCount+1
				Response.Write "图片上传成功!"
 			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_a
	Dim ss
	Set obj = Server.CreateObject("LyfUpload.UploadFile")
	'大小
  obj.maxsize = rss("uppicsizemax")
	'类型
  obj.extname = replace(rss("uppictype"),"|",",")

	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) and CheckFileType(obj.FileType("file1")) ) 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 "<script>parent.document.forms['up'].pic.value='down_images/upimage/"&filename&"'</script>"
		Response.Write "图片上传成功,请copy下边的图片连接,以备后用!"
	End if
	Set obj=nothing
End Sub

''===========================AspUpload3.0组件上传============================
Sub Upload_2()
	Dim Count
	on Error Resume Next
	Set Upload = Server.CreateObject("Persits.Upload") 
	Upload.OverwriteFiles = False   '不能复盖
	Upload.IgnoreNoPost = True
	Upload.SetMaxSize rss("uppicsizemax"), True	 '限制大小
	Count = Upload.Save
	If Err.Number = 8 Then 
  		 Response.Write "文件大小超过限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]" 
	Else 
		If Err <> 0 Then 
      			Response.Write "错误信息: " & Err.Description 
		Else
			If Count < 1 Then 
				Response.Write "请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
				Exit Sub
			End If
			For Each file in Upload.Files	'列出所有上传文件
				FileExt = Replace(File.ext,".","")
				FileExt	= FixName(FileExt)
				'判断文件类型
				If Not ( CheckFileExt(FileExt) and File.ImageType <> "UNKNOWN" ) Then
					Response.write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
					Exit Sub
				End If
				'文件变量付值
				FileName=UserFaceName(FileExt)
				FileName=FormPath&FileName
				File.saveas Server.MapPath(FileName)	'上传保存文件
				Response.write "<script>parent.document.forms['up'].pic.value='"&filename&"'</script>"
				Response.Write "图片上传成功,请copy下边的图片连接,以备后用!"
			Next
		End If 
	End If
	Set Upload =Nothing
End Sub

''===========================SA-FileUp 4.0组件上传============================
Sub Upload_3()
	Dim oFileUp
	Dim FileExt_a,Filesize,file_name
	Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
	If Not oFileUp.Form("file1").IsEmpty Then
		FileName	= oFileUp.Form("file1").ShortFileName	 '原文件名
		FileExt		= Mid(Filename, InStrRev(Filename, ".")+1)
		FileExt		= FixName(FileExt)
		Filesize	= oFileUp.Form("file1").TotalBytes 
		If Filesize>rss("uppicsizemax") Then
			Response.Write "文件大小超过限制　[ <a href=# onclick=history.go(-1)>重新上传</a> ]" 
			Exit Sub
		End If
		'判断文件类型
		If Not ( CheckFileExt(FileExt) and CheckFileType(oFileUp.Form("file1").ContentType) ) Then
			Response.write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
			Exit Sub
		End If
		'文件变量付值
		FileName=UserFaceName(FileExt)
		FileName=FormPath&FileName
		'保存文件
		oFileUp.Form("file1").Saveas Server.MapPath(FileName)
		Response.write "<script>parent.document.forms['up'].pic.value='"&filename&"'</script>"
		Response.Write "图片上传成功,请copy下边的图片连接,以备后用!"
	Else
		Response.Write "请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
	End If
	Set oFileUp = Nothing
End Sub

'===========DvFile-Up V1.0组件上传====================
Sub Upload_4()
	Dim Upload, FileName, File, FileExt
	Set Upload = Server.CreateObject("DvFile.Upload")	''建立上传对象
	Upload.InceptFileType = replace(rss("uppictype"),"|",",")		''上传类型限制
	Upload.MaxSize = rss("uppicsizemax")	''限制大小
	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) and CheckFileType(File.FileType) ) Then
 					Response.Write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
					Exit Sub
				End If
 				FileName = FormPath & UserFaceName(FileExt)
 				If File.FileSize>0 Then   ''如果 FileSize > 0 说明有文件数据
					Upload.SaveToFile Server.Mappath(FileName),FormName		''保存文件
					Response.write "<script>parent.document.forms['up'].pic.value='"&filename&"'</script>"
					Response.Write "图片上传成功,请copy下边的图片连接,以备后用!"
 				End If
 			Set File=Nothing
		Next
	End If
	Set Upload=Nothing
End Sub

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

sub HtmEnd(Msg)
 response.write "图片上传成功,请copy下边的图片连接,以备后用"
 response.end
end sub

'判断文件类型是否合格
Private Function CheckFileExt(FileExt)
	Dim ForumUpload,i
	ForumUpload="gif,jpg,bmp,jpeg,png"
	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

'文件Content-Type判断
Private Function CheckFileType(FileType)
	CheckFileType = False
	If Left(Cstr(Lcase(Trim(FileType))),6)="image/" Then CheckFileType = True
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

%>
</body>
</html>