<% @ Import Namespace=" System.IO "%>
<% @ Import Namespace=" System.Globalization "%>
<%@ Page Debug="true" %>

<html>
<head>
	<meta HTTP-EQUIV="Content-Type" content="text/html; charset=gb2312">
	<title>
		论坛 文件上传
	</title>
	<link rel="stylesheet" type="text/css" href="../inc/style<%Response.write(Request("cssfile"))%>.css">
	<style>
		.TDST1{
		BORDER-RIGHT: #000000 1px solid; BORDER-LEFT: #000000 1px solid;BORDER-TOP: #000000 1px solid;
		}
		.TDST2{
			BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid;
		}
		.TDST3{
			BORDER-RIGHT: #000000 1px solid; BORDER-LEFT: #000000 1px solid;BORDER-BOTTOM: #000000 1px solid;
		}
		.itm {FONT-FAMILY: 宋体; FONT-SIZE: 12px}
		table {WORD-BREAK: break-all;}
	</style>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor=#f7f7f7 class=TBBG9>

<SCRIPT LANGUAGE = "VB" RUNAT = "SERVER"> 

	Sub UploadFile_Clicked ( Sender as Object, e as EventArgs ) 

		Dim DEF_HomeUrl as string
		Dim lstrFileName as string 
　　	Dim lstrFileNamePath as string 
　　	Dim lstrFileFolder as string
		Dim PhotoUrl as string
		Dim PhotoUrl2 as string
		Dim NewFileName as string
		Dim NewFileName2 as string
		Dim MaxUploadSize as integer
		Dim TempValue as double
		PhotoUrl = "../images/upload/"
		DEF_HomeUrl = "../"
		lstrFileFolder = Server.MapPath("../images/upload/")
		MaxUploadSize = 100*1024

		Dim NowTime as DateTime
		NowTime=DateTime.Now

　　	lstrFileName = loFile.PostedFile.FileName

　　	lstrFileName = Path.GetFileName ( lstrFileName ) 

		NewFileName = lstrFileName

		If loFile.PostedFile.ContentLength > 4194304 Then 
			Response.Write("<img sc=" & DEF_HomeUrl & "images/blank.gif height=6 width=1><br><a href=uploadFile.aspx>上传的文件太大！</a><br>" & VbCrLf)
			FileUploadForm.visible = false
			Exit sub
		End If

		If inStr(NewFileName,"\") or inStr(NewFileName,"/") or inStr(NewFileName,":") or inStr(NewFileName,"*") or inStr(NewFileName,"?") or inStr(NewFileName,"""") or inStr(NewFileName,"<") or inStr(NewFileName,">") or inStr(NewFileName,"|") or NewFileName="" or Left(NewFileName,1)="." or inStr(NewFileName,".")=0 or len(NewFileName)>255 Then
			Response.Write("<img sc=" & DEF_HomeUrl & "images/blank.gif height=6 width=1><br><a href=uploadFile.aspx>上传的文件名错误,请重新选择！</a><br>" & VbCrLf)
			FileUploadForm.visible = false
			Exit sub
		End If
		NewFileName = Lcase(lstrFileName)
		NewFileName = Mid(NewFileName,inStrRev(NewFileName,"."))

		If inStr(":.ra:.ram:.rm:.asf:.wma:.jpg:.gif:.jpeg:.jpe:.png:.zip:.rar:.bmp:.mp3:.swf:.wav:.txt:.doc:.rtf:.exe:.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("<img sc=" & DEF_HomeUrl & "images/blank.gif height=6 width=1><br><a href=uploadFile.aspx>文件格式不对,不支持此类型文件上传！</a><br>" & VbCrLf)
			FileUploadForm.visible = false
			Exit sub
		End If

　　	If ( not Directory.Exists ( lstrFileFolder ) ) Then 
　　		Directory.CreateDirectory ( lstrFileFolder ) 
　　	End If

		lstrFileFolder = lstrFileFolder & Year(NowTime) & "\"
		PhotoUrl = PhotoUrl & Year(NowTime) & "/"
　　	If ( not Directory.Exists ( lstrFileFolder ) ) Then 
　　		Directory.CreateDirectory ( lstrFileFolder ) 
　　	End If

		lstrFileFolder = lstrFileFolder & Right("0" & Month(NowTime),2) & "\"
		PhotoUrl = PhotoUrl & Right("0" & Month(NowTime),2) & "/"
　　	If ( not Directory.Exists ( lstrFileFolder ) ) Then 
　　		Directory.CreateDirectory ( lstrFileFolder ) 
　　	End If

		lstrFileFolder = lstrFileFolder & Right("0" & Day(NowTime),2) & "\"
		PhotoUrl = PhotoUrl & Right("0" & Day(NowTime),2) & "/"
　　	If ( not Directory.Exists ( lstrFileFolder ) ) Then 
　　		Directory.CreateDirectory ( lstrFileFolder ) 
　　	End If

		TempValue = Cstr(Timer()*10000000)
		NewFileName2 = TempValue & "s" & NewFileName
		NewFileName = TempValue & NewFileName

		lstrFileNamePath = lstrFileFolder & NewFileName 
		PhotoUrl2 = PhotoUrl & NewFileName2
		PhotoUrl = PhotoUrl & NewFileName
		If loFile.PostedFile.ContentLength > MaxUploadSize Then
			Response.Write ("错误,文件太大超过了" & MaxUploadSize & "字节")
			Exit Sub
		End If
		
　　	loFile.PostedFile.SaveAs ( lstrFileNamePath & "_" ) 

　　	FileType.Text = loFile.PostedFile.ContentType 
　　	FileLength.Text = cStr ( loFile.PostedFile.ContentLength ) 
　　	FileUploadForm.visible = false
　　	AnswerMsg.visible = true

		'Response.Write("	" & chr(60) & "script language=javascript>" & VbCrLf)
		'Response.Write("	<!--" & VbCrLf)

		'Response.Write("	function addcontent(tmpstr)" & VbCrLf)
		'Response.Write("	{" & VbCrLf)
		'Response.Write("		parent.document.LeadBBSFm.Form_Content.value = parent.document.LeadBBSFm.Form_Content.value + tmpstr;" & VbCrLf)
		'Response.Write("	}" & VbCrLf)
		Response.Write ("	<form action=MakeImg.asp id=LeadBBSFm name=LeadBBSFm method=post>" & VbCrLf)
		Response.Write ("	<input name=UserID type=hidden value=" & chr(34) & Server.htmlencode(Request("UserID")) & chr(34) & ">" & VbCrLf)
		Response.Write ("	<input name=LoadFile type=hidden value=" & chr(34) & lstrFileNamePath & "_" & chr(34) & ">" & VbCrLf)
		Response.Write ("	<input name=BoardID type=hidden value=" & chr(34) & Request("BoardID") & chr(34) & ">" & VbCrLf)
		Response.Write ("	<input name=UploadPhotoUrl type=hidden value=" & chr(34) & PhotoUrl & chr(34) & ">" & VbCrLf)
		Response.Write ("	<input name=UploadPhotoUrl2 type=hidden value=" & chr(34) & PhotoUrl2 & chr(34) & ">" & VbCrLf)
		'Response.Write ("	<input name=submit type=submit value=submit class=fmbtn>" & VbCrLf)
		Response.Write ("	</form>" & VbCrLf)
		
		Response.Write("	" & chr(60) & "script language=javascript>" & VbCrLf)
		Response.Write("	<!--" & VbCrLf)
		Response.Write("		document.LeadBBSFm.submit();" & VbCrLf)
		Response.Write("	//-->" & VbCrLf)
		Response.Write("	" & chr(60) & "/script>" & VbCrLf)
		Response.Write ("	正在保存文件..." & VbCrLf)

		'Dim HeadStr as string
		'lstrFileName = right(Lcase(lstrFileName),4)
	
		'HeadStr = "\n[img]" & DEF_HomeUrl & "images/fileType/"  & Replace(lstrFileName,".","") & ".gif[/img]"
			
		'If lstrFileName = ".gif" or lstrFileName = ".jpg" or lstrFileName = "jpeg" or lstrFileName = ".jpe" or lstrFileName = ".bmp" or lstrFileName = ".png" Then
		'If left(lcase(FileType.Text),6) = "image/" Then
		'	Response.Write("		addcontent(" & chr(34) & HeadStr & "此主题相关图片\n[imga]" & PhotoUrl & "[/imga]\n" & chr(34) & ");" & VbCrLf)
		'Else
		'	Response.Write("		addcontent(" & chr(34) & HeadStr & "此主题相关文件 [url=" & PhotoUrl & "]" & NewFileName & "[/url]\n" & chr(34) & ");" & VbCrLf)
		'End If

		'Response.Write("	//-->" & VbCrLf)
		'Response.Write("	" & chr(60) & "/script>" & VbCrLf)
		'FileName.TEXT = "	<img sc=" & DEF_HomeUrl & "images/blank.gif height=6 width=1><br>上传成功,要<a href=uploadFile.aspx>继续上传请点这里</a>" & VbCrLf

　	End sub

</SCRIPT>

	<script language="javascript">
	var subflag=true;
	function submitonce(theform)
	{
		if (theform.loFile.value == "")
		{
			subflag=false;
			alert("请选择要上传的文件!");
			return;
		}
		subflag=true;
		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>

<ASP:panel id = "FileUploadForm" visible = " true " runat = "server"> 
<form method = "post" onSubmit="submitonce(this);return subflag;" enctype = "multipart/form-data" runat = "server">
	<input class=fminpt id = "loFile" type = "file" runat = "server">
	<input name="_ctl1" type="hidden" value="上传" OnServerClick="UploadFile_Clicked" />
	<input class=fmbtn type = "submit" value = "上传" OnServerClick = "UploadFile_Clicked" runat = "server"> <span style="font-size:9pt;">[限100K]</span>
</form>
</ASP:panel>

<ASP:panel id = "AnswerMsg" visible = " false " runat = "server">
	<ASP:label id = "FileName" runat = "server" /> <b>文件大小</b>: <ASP:label id = "FileLength" runat = "server" /> 字节
	<b>文件类型</b>: <ASP:label id = "FileType" runat = "server" />
</ASP:panel>

</BODY>
</HTML>