<!--#include FILE="conn.asp"-->
<!--#include FILE="inc/const.asp"-->
<!--#include FILE="upload.inc"-->
<%
Dvbbs.LoadTemplates("usermanager")
Dvbbs.Stats=Dvbbs.MemberName&template.Strings(1)
Dvbbs.Head()
%>
<table width=100% border=0  cellspacing="0" cellpadding="0"><tr><td class=tablebody1 width=100% height=100% >
<script>
parent.document.theForm.Submit.disabled=false;
parent.document.theForm.Submit2.disabled=false;
</script>
<%
dim upload_type,uploadfinish
dim upload,file,formName,formPath,iCount,filename,fileExt
dim ranNum
uploadfinish=false
'---------------------------------------------------------------
'上传组件选择:upload_type=参数
'参数说明:0＝无组件，1＝Lyfupload，2＝Aspupload3.0，3＝SA-FileUp 4.0
upload_type=0	'默认设置为无组件上传
'---------------------------------------------------------------

if session("upface")="done" then
	response.write "您已经上传了头像"
	response.end
end if

select case upload_type
case 0
	call upload_0()
case 1
	call upload_1()
case 2
	call upload_2()
case 3
	call upload_3()
case else
	response.write "本系统未开放插件功能"
	Response.Write "</body></html>"
	CloseDatabase
	response.end
end select

'===========无组件上传(upload_0)====================
sub upload_0()
set upload=new UpFile_Class ''建立上传对象
upload.GetDate (int(Dvbbs.Forum_Setting(56))*1024)   '取得上传数据,不限大小
iCount=0
 
if upload.err > 0 then
    select case upload.err
	case 1
	Response.Write "请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
	case 2
	Response.Write "图片大小超过了限制 "&Dvbbs.Forum_Setting(56)&"K　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
	end select
	exit sub
	else
formPath=upload.form("filepath")
 ''在目录后加(/)
 if right(formPath,1)<>"/" then formPath=formPath&"/" 

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> ]"
	Response.Write "</body></html>"
	CloseDatabase
	response.end
 end if

 fileExt=lcase(file.FileExt)
if CheckFileExt(fileEXT)=false then
 	response.write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
	Response.Write "</body></html>"
	CloseDatabase
	response.end
end if

randomize
ranNum=int(90000*rnd)+10000
 filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
 if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
	file.SaveToFile Server.mappath(filename)   ''保存文件
	response.write "<script>parent.document.images['face'].src='" &filename& "';parent.document.theForm.myface.value='"&FileName&"'</script>"
	uploadfinish=true
	session("upface")="done"
	response.write "图片上传成功!"
 end if
 set file=nothing
next
set upload=nothing
end if
end sub

'===========Lyfupload组件上传(upload_1)=========================
sub upload_1()
	dim obj,filename,fileExt_a
	dim ss
	Set obj = Server.CreateObject("LyfUpload.UploadFile")
	'大小
    	obj.maxsize=int(Dvbbs.Forum_Setting(56))*1024
	'类型
    	obj.extname="gif,jpg,bmp,jpeg"
	'重命名
	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
	randomize
	ranNum=int(90000*rnd)+10000
	fileExt_a=split(obj.request("fname"),".")
	fileExt=lcase(fileExt_a(ubound(fileExt_a)))
	filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
	filename=filename&"."&fileExt

	ss=obj.SaveFile("file1",Server.MapPath(formPath), true,filename)

	if ss= "3" then
   		Response.Write ("文件名重复![ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		Response.Write "</body></html>"
		CloseDatabase
		response.end
	elseif ss= "0" then
   		Response.Write ("文件尺寸过大![ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		Response.Write "</body></html>"
		CloseDatabase
		response.end
	elseif ss = "1" then
 		Response.Write ("文件不是指定类型文件![ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		Response.Write "</body></html>"
		CloseDatabase
		response.end
	elseif ss = "" then
 		Response.Write ("文件上传失败![ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		Response.Write "</body></html>"
		CloseDatabase
		response.end
	else
		uploadfinish=true
		Response.Write "图片上传成功!" 
		response.write "<script>parent.document.images['face'].src='" &filename& "';parent.document.theForm.myface.value='" &formPath&filename & "'</script>"
		session("upface")="done"
		Response.Write "</body></html>"
		CloseDatabase
	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 int(Dvbbs.Forum_Setting(56))*1024, True	 '限制大小

Count = Upload.Save
If Err.Number = 8 Then 
   Response.Write "文件大小超过了限制 "&Dvbbs.Forum_Setting(56)&"K　[ <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> ]"
		Response.Write "</body></html>"
		CloseDatabase
		response.end
		End If   
	formPath=Upload.form("filepath")
	if right(formPath,1)<>"/" then formPath=formPath&"/" 
	For Each file in Upload.Files	'列出所有上传文件
	fileExt=lcase(replace(File.ext,".",""))
	'判断文件类型
	if CheckFileExt(fileEXT)=false then
 	response.write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
	Response.Write "</body></html>"
	CloseDatabase
	response.end
	end if
	'文件变量付值
	randomize
	ranNum=int(90000*rnd)+10000
	filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&File.ext
	filename=formPath&filename
	file.saveas Server.MapPath(filename)	'上传保存文件
	response.Write "图片上传成功!"
	response.write "<script>parent.document.images['face'].src='" &filename& "';parent.document.theForm.myface.value='" &filename& "'</script>"
	session("upface")="done"
	uploadfinish=true
	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")
formPath=oFileUp.Form("filepath")
if right(formPath,1)<>"/" then formPath=formPath&"/" 
'oFileUp.Path = Server.MapPath(formPath)
If Not oFileUp.Form("file1").IsEmpty Then

			filename=oFileUp.Form("file1").ShortFileName	 '原文件名
			fileExt_a=split(filename,".")
			fileExt=lcase(fileExt_a(ubound(fileExt_a)))
			fileExt=replace(fileExt,".","")
			Filesize=oFileUp.Form("file1").TotalBytes 

			if Filesize>int(Dvbbs.Forum_Setting(56))*1024 then
			Response.Write "文件大小超过了限制 "&Dvbbs.Forum_Setting(56)&"K　[ <a href=# onclick=history.go(-1)>重新上传</a> ]" 
			exit sub
			end if

			'判断文件类型
			if CheckFileExt(fileEXT)=false then
			response.write "文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
			exit sub
			end if

			'文件变量付值
			randomize
			ranNum=int(90000*rnd)+10000
			file_name=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
			filename=file_name&"."&fileExt
			filename=formPath&filename
			
			'保存文件
			oFileUp.Form("file1").Saveas Server.MapPath(filename)
			response.Write "图片上传成功!" 
			uploadfinish=true
			'response.write "<script>parent.document.forms[0].myface.value='" &filename& "'</script>"
			response.write "<script>parent.document.images['face'].src='" &filename& "';parent.document.theForm.myface.value='" &filename& "'</script>"
			session("upface")="done"
			Htmend iCount&" 个文件上传结束!"

Else
            Response.Write "请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
End If
Set oFileUp = Nothing

end sub

'******************
'删除用户旧的头像
'dim filepaths,objFSO,upface,rs
'if  Dvbbs.founduser and uploadfinish=true then
'on error resume next
'Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'set rs=Dvbbs.execute("select Userface from [Dv_user] where userid="&Dvbbs.userid)
    'upface=rs(0)
'if instr(Lcase(upface),"uploadface") then
	'filepaths=Server.MapPath(""&upface&"")
	'if objFSO.fileExists(filepaths) then
	'response.write "删除"&filepaths
	'response.write "旧文件已被删除！"
	'objFSO.DeleteFile(filepaths)
	'end if
'end if
'rs.close
'set rs=nothing
'set objFSO = nothing
'end if
'******************
'删除用户旧的头像


'判断文件类型是否合格
Private Function CheckFileExt (fileEXT)
dim Forumupload,i
Forumupload="gif,jpg,bmp,jpeg"
Forumupload=split(Forumupload,",")
	for i=0 to ubound(Forumupload)
		if lcase(fileEXT)=lcase(trim(Forumupload(i))) then
			CheckFileExt=true
			exit Function
		else
			CheckFileExt=false
		end if
	next
End Function

%>
</td></tr></table>
</body>
</html>