<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<%DEF_BBS_HomeUrl = "../"%>
<!-- #include file=../inc/Upload_Fun.asp -->
<!-- #include file=../announce/inc/upload1_fun.asp -->
<%
UploadPhotoUrl = UploadPhotoUrl & "face/"
PhotoDirectory = PhotoDirectory & "face/"
Dim TempStr

If DEF_FSOString = "" Then Response.End
If DEF_EnableUpload = 0 Then Response.End
If DEF_EnableDotNetUpload <> 2 Then Response.End%>
<script language=javascript>
<!--

	function addcontent(tmpstr,GBL_Width,GBL_Height)
	{
		parent.document.form1.Form_FaceUrl.value = tmpstr;
		parent.document.form1.Form_FaceWidth.value = GBL_Width;
		parent.document.form1.Form_FaceHeight.value = GBL_Height;
		parent.document.faceimg.src=tmpstr;
		parent.document.faceimg.width=GBL_Width;
		parent.document.faceimg.height=GBL_Height;
	}

//-->
</script>
<%
Rem 缩小图像模式,0-缩小到预定宽或高,1,如果大于预定宽或高则成倍缩小
Const DEF_ResizeMode = 0

initDatabase
If DEF_EnableUpload = 2 Then
	If GBL_UserID<1 or CheckSupervisorUserName = 0 Then
		CloseDatabase
		Response.End
	End If
End If

SiteHead("   ")%>
<body bgcolor=<%=DEF_BBS_LightestColor%> leftmargin="0" topmargin="0">
<%
If Request.QueryString("submitflag") = "" Then
	photoUpformFunction
Else
	If GBL_CHK_LastWriteTime < DEF_WriteEventSpace Then
		Response.Write "<b><font color=Red Class=RedFont>您的操作太频，请稍候再上传!</font></b> <br>" & VbCrLf
		CloseDatabase
		Response.End
	End If
	SaveUploadFile
End If%>
</body>
</html>
<%
CloseDatabase

Function photoUpformFunction

%>
	<script language=JavaScript>
	<!--
	ValidationPassed = true;
	function visagePhotoForm_onsubmit(obj)
	{
		ValidationPassed = true;
		if(obj.photo.value =="")
		{
			alert("请点击浏览按钮选择要上传的文件!\n");
			ValidationPassed = false;
			obj.photo.focus();
			return;
		}
		ValidationPassed = true;
		return true;
	}

	function submitonce(theform)
	{
		if(ValidationPassed == false)return;
		if (document.all||document.getElementById)
		{
			for (i=0;i<theform.length;i++)
			{
				var tempobj=theform.elements[i];
				if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
				tempobj.disabled=true;
			}
		}
	}
	-->
	</script>
	<table cellspacing=1 cellpadding=0 width="100%" border=0 valign=absmiddle height=100%>
	<tbody>
	<form method=POST action=uploadFile1.asp?submitflag=yes&dontRequestFormFlag=<%="Guest" & Second(time) & hour(time) & minute(time)%> name=visagePhotoForm enctype=multipart/form-data onSubmit="submitonce(this);return ValidationPassed;">
	<tr>
		<td valign=absmiddle align=absmiddle>
			<input type=file size=11 name=photo class=fminpt>
			<input class=fmbtn type=submit value=上传 name=send onclick="visagePhotoForm_onsubmit(this.form)"> [限<%=Left((DEF_FaceMaxBytes/1024/1024),3)%>M]
			<br>
	</td>
	</tr>
	</form>
	</table>

<%End Function

Function SaveUploadFile

	uploadfilenow
	
	If CheckSupervisorUserName = 0 Then
		Con.ExeCute("Update LeadBBS_User Set LastWriteTime=" & GetTimeValue(now) & " where ID=" & GBL_UserID)
	End If
	Response.Write "<img sc=" & DEF_BBS_HomeUrl & "images/blank.gif height=6 width=1><br><a href=uploadFile1.asp>" & TempStr & "</a>"

End Function

function getfilenameloop(name)

	Dim fs
	Set fs = CreateObject(DEF_FSOString)
	dim tempname,n,extendFileName
	name = Lcase(name)
	tempname = name
	name = "1" & Mid(name,inStrRev(name,"."))
	extendFileName = Mid(name,inStrRev(name,"."))
	n=0
	dim tdir
	tdir=server.mappath(PhotoDirectory) & "\"
	if Not fs.FolderExists(tdir) then
		getfilenameloop = 0
		TempStr = TempStr & "错误，存放图标的目录不存在，请联系网站中心！<br>" & VbCrLf
		'fs.CreateFolder(tdir)
	end if
	
	tdir = tdir & year(date) & "\"
	UploadPhotoUrl = UploadPhotoUrl & year(date) & "/"
	If Not fs.FolderExists(tdir) then
		fs.CreateFolder(tdir)
	End If

	tdir = tdir & right("0" & month(date),2) & "\"
	UploadPhotoUrl = UploadPhotoUrl & right("0" & month(date),2) & "/"
	if Not fs.FolderExists(tdir) then
		fs.CreateFolder(tdir)
	end if
	
	tdir = tdir & right("0" & day(date),2) & "\"
	UploadPhotoUrl = UploadPhotoUrl & right("0" & day(date),2) & "/"
	if Not fs.FolderExists(tdir) then
		fs.CreateFolder(tdir)
	end if
	
	PhotoDir = tdir

	Dim TempNum,Temp
	
	'TempNum = right(GetTimeValue(now),6)
	TempNum = Timer()*100000000
	
	getfilenameloop = TempNum & extendFileName
	pic_name2 = TempNum & "s" & extendFileName

	if fs.FileExists(tdir & getfilenameloop) then
		for Temp = 0 to 99
			getfilenameloop = TempNum & "_" & Temp & extendFileName
			pic_name2 = TempNum & "_" & Temp & "s" & extendFileName
			if fs.FileExists(tdir & getfilenameloop) then
			Else
				set fs = nothing
				Exit Function
			End If
		Next
		'delphotofromharddisk(stemp)
		'TempStr =  TempStr &  "错误！目标文件已经存在，请重新刷新一次！<br>" & VbCrLf
		set fs = nothing
	else
		set fs = nothing
	end if

end function

dim fileup,pic_name1,pic_name,PhotoDir,pic_name2,UploadPhotoUrl2

function uploadfilenow

	Dim NewFileName
	'on error resume next
	Dim iCount,formPath,formName,file,FileExt

	set fileup=new UpFile_Class ''建立上传对象
	fileup.GetData (DEF_FaceMaxBytes)   '取得上传数据,不限大小
	 
	If fileup.err > 0 then
	    select case fileup.err
			case 1
					Response.Write "请先选择你要上传的文件　[ <a href=#3234 onclick=history.go(-1)>重新上传</a> ]"
			case 2
					Response.Write "图片大小超过了限制 " & DEF_FaceMaxBytes & "K　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
		end select
		exit function
	Else
		For each formName in fileup.file ''列出所有上传了的文件
			set file=fileup.file(formName)  ''生成一个文件对象
			if file.filesize<1 then
				response.write "请先选择你要上传的文件　[ <a href=#s334 onclick=history.go(-1)>重新上传</a> ]"
				response.end
	 		end if
	
	 		NewFileName="." & lcase(file.FileExt)
			if inStr(":.jpg:.gif:.jpeg:.jpe:.png:.bmp:.wav:.psd:.tif:.mid:.sgi:.tga:.iff:.pcx:.dcx:.pbm:.pgm:.ppm:.pnm:.miff:.xbm:.xpm:.ico:.icl:.emf:.hru:.jif:.prc:.wrl:.wbmp:",":" & NewFileName & ":") = 0 then
	 			response.write "文件格式不正确　[ <a href=#3333 onclick=history.go(-1)>重新上传</a> ]"
				response.end
			end if
	
			pic_name1=getfilenameloop(NewFileName)
			UploadPhotoUrl2 = UploadPhotoUrl & pic_name2
			UploadPhotoUrl = UploadPhotoUrl & pic_name1
			pic_name = pic_name1
			
			if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
				file.SaveToFile PhotoDir & pic_name   ''保存文件
			end if
			Set File = Nothing
		Next
		Set Fileup = Nothing
	End If
	%>
	<script language=javascript>
	<!--
	<%
	Dim HeadStr,Temp,Old_pic_name
	Old_pic_name = pic_name
	If inStrRev(pic_name,".")>0 Then pic_name = Mid(pic_name,inStrRev(pic_name,".")+1)
	
	HeadStr = "\n[img]" & DEF_BBS_HomeUrl & "images/fileType/"  & Replace(pic_name,".","") & ".gif[/img]"
	
	If DEF_EnableGFL = 1 Then
		If inStr(":jpg:gif:jpeg:jpe:png:bmp:psd:tif:sgi:tga:iff:pcx:dcx:pbm:pgm:ppm:pnm:miff:xbm:xpm:ico:icl:emf:hru:jif:prc:wrl:wbmp:",pic_name) > 0 Then
			Temp = SaveSmallPic(PhotoDir & Old_pic_name,PhotoDir & pic_name2,DEF_AllFaceMaxWidth,DEF_AllFaceMaxWidth)
			If Temp = 4 Then
				If inStrRev(UploadPhotoUrl2,".")>0 Then
					UploadPhotoUrl2 = Left(UploadPhotoUrl2,inStrRev(UploadPhotoUrl2,".")) & "jpg"
				Else
					UploadPhotoUrl2 = UploadPhotoUrl2 & "jpg"
				End if
				If inStrRev(pic_name2,".")>0 Then
					pic_name2 = Left(pic_name2,inStrRev(pic_name2,".")) & "jpg"
				Else
					pic_name2 = pic_name2 & "jpg"
				End if
			ElseIf Temp = 3 Then
				If inStrRev(UploadPhotoUrl2,".")>0 Then
					UploadPhotoUrl2 = Left(UploadPhotoUrl2,inStrRev(UploadPhotoUrl2,".")) & "gif"
				Else
					UploadPhotoUrl2 = UploadPhotoUrl2 & "gif"
				End if
				If inStrRev(pic_name2,".")>0 Then
					pic_name2 = Left(pic_name2,inStrRev(pic_name2,".")) & "gif"
				Else
					pic_name2 = pic_name2 & "gif"
				End if
			Else
				If Temp = 1 Then
					If inStrRev(UploadPhotoUrl2,".")>0 Then
						UploadPhotoUrl2 = Left(UploadPhotoUrl2,inStrRev(UploadPhotoUrl2,".")) & "jpg"
					Else
						UploadPhotoUrl2 = UploadPhotoUrl2 & "jpg"
					End if
					If inStrRev(pic_name2,".")>0 Then
						pic_name2 = Left(pic_name2,inStrRev(pic_name2,".")) & "jpg"
					Else
						pic_name2 = pic_name2 & "jpg"
					End if
				End If
			End If
			If Temp = 1 or Temp = 3 or Temp = 4 Then
				If GBL_Width < 20 or GBL_Height < 20 Then
					Response.Write "alert(""图像宽度或高度太小或比例不相称,最小要求20像素!"");"
					deletefiles PhotoDir & pic_name2
				Else
					CheckUploadDatabase PhotoDir & pic_name2,""
					Response.Write "addcontent(""" & UploadPhotoUrl2 & """," & GBL_Width & "," & GBL_Height & ");"
				End If
				deletefiles(PhotoDir & Old_pic_name)
			Else
				If Temp = 2 Then
					If GBL_Width < 20 or GBL_Height < 20 Then
						Response.Write "alert(""图像宽度或高度太小或比例不相称,最小要求20像素!"");"
						deletefiles PhotoDir & pic_name2
						deletefiles(PhotoDir & Old_pic_name)
					Else
						CheckUploadDatabase PhotoDir & Old_pic_name,""
						Response.Write "addcontent(""" & UploadPhotoUrl & """," & GBL_Width & "," & GBL_Height & ");"
					End If
				Else
					Response.Write "alert(""非图像文件,上传错误!"");"
					deletefiles(PhotoDir & Old_pic_name)
				End If
			End If
		Else
			Response.Write "alert(""非图像文件,上传错误!"");"
			deletefiles(PhotoDir & Old_pic_name)
		End If
	Else
		If pic_name = "gif" or pic_name = "jpg" or pic_name = "jpeg" or pic_name = "jpe" or pic_name = "bmp" or pic_name = "png" Then
			CheckUploadDatabase PhotoDir & Old_pic_name,""
			Response.Write "addcontent(""" & UploadPhotoUrl & """," & DEF_AllFaceMaxWidth & "," & DEF_AllFaceMaxWidth & ");"
		Else
			Response.Write "alert(""非图像文件,上传错误!"");"
			deletefiles(PhotoDir & Old_pic_name)
		End If
	End If
	%>

	//-->
	</script>
	文件上传成功,要<a href=uploadFile1.asp>继续上传请点这里</a>
	<%

end function
%>