<!-- #include file="inc/inc_syssite.asp" -->
<!-- #include File="inc/class_upfile.asp" -->
	<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
	<title>Oblog4.0 文件上传</title>
	</head>
	<body>
<style type="text/css">
<!--
/* 全局 */
div,ul,ol,form {margin:0;padding:0;}
input {font-family:Arial,Helvetica,sans-serif;font-size:12px;height:20px;}

body {
text-align: center;
margin:0;
font-family:Arial,Helvetica,sans-serif;
font-size: 12px;
line-height: 150%;
word-break:break-all;
}
-->
</style>
<%
if not oblog.checkuserlogined() then
	response.Write("登录后才能上传文件")
	response.End()
end if
Dim tMode,rs,sysclass,subject
tMode=Request("tMode")
dim freesize,onesize,maxsize,enupload,upfiletype,re,ubb,isphoto
re=request.QueryString("re")
ubb=request.QueryString("ubb")
isphoto=cint(request.QueryString("isphoto"))
sysclass=request.QueryString("sysclass")
if sysclass<>"" then sysclass=clng(sysclass) else sysclass=0
subject=request.QueryString("subject")
if subject<>"" then subject=clng(subject) else subject=0
If oblog.l_Group(24,0)=-1 Then 
	enupload=0
Else
	enupload=1
End If
upfiletype=oblog.l_Group(22,0)
'Response.Write upfiletype
'Response.End
onesize=oblog.l_Group(23,0)
maxsize=oblog.l_Group(24,0)
if enupload=0 then
	response.Write("当前系统设置不允许上传文件")
	response.End()
end if
'maxsize不限制大小,不进行检测
If maxsize<>0 Then
	freesize=int(maxsize-oblog.l_uUpUsed/1024)
	if freesize<=0 then
		response.Write("<ul style='margin:0px;text-align: left;width:100%;'> 上传空间已满，不允许上传文件,请整理上传文档</ul></body></html>")
		response.End()
	end if
End If
Dim g_up_types,arr_g_up_types,str_g_up_types
Dim trs,ii
Set trs = oblog.execute ("SELECT g_up_types FROM oblog_groups WHERE groupid = " & oblog.l_uGroupId)
str_g_up_types = trs (0)
trs.close 
Set trs=Nothing
If InStr(str_g_up_types,"|")>0 Then 
	arr_g_up_types=Split (str_g_up_types,"|")
	For ii= 0 To UBound(arr_g_up_types)
		g_up_types = g_up_types &"."& arr_g_up_types (ii)
	Next 
Else 
	g_up_types="." &str_g_up_types	
End if
If Request("t")="1" Then
	Upfile_Main()
Else
	if tMode=1 then
		Main_photo 
	else 
		Main()
	end if
End If

Sub Main()
	Dim PostRanNum
	Randomize
	PostRanNum = Int(900*rnd)+1000
	Session("UploadCode") = Cstr(PostRanNum)
%>
	<ul style="margin:0px;text-align: left;width:100%;"> 
      <form name="myform" method="post" action="upload.asp?t=1&tMode=<%=tMode%>&re=<%=re%>&ubb=<%=ubb%>&isphoto=<%=isphoto%>" enctype="multipart/form-data">
	<INPUT TYPE="hidden" NAME="UploadCode" value="<%=PostRanNum%>">
	<input type="hidden" name="act" value="upload">
	<%If Request("tmode")<>"9" Then%>
	上传文件：
	<%End If%>
	 <input type="file" name="uploadfile">
	<input type="hidden" name="fname">
	<input type="submit" name="Ok" value="上传" ><br />
	<%If Request("tmode")<>"9" Then%>
	剩余空间：<%
	If maxsize=0 Then
		Response.Write "不限制"
	Else
		Response.Write freesize& "KB"
	End If
	%> 单个文件：<%=onesize%>KB 
	<br />允许上传文件格式：<%=g_up_types%>
	<%end if%>
      </form>
	</ul>
</body>
</html>
<%
End Sub

sub main_photo()
	Dim PostRanNum,subjectid
	Randomize
	PostRanNum = Int(900*rnd)+1000
	Session("UploadCode") = Cstr(PostRanNum)
%>
	<ul style="margin:0px;text-align: left;width:100%;"> 
	剩余空间：<%
	If maxsize=0 Then
		Response.Write "不限制"
	Else
		Response.Write freesize& "KB"
	End If
	%> 单个文件：<%=onesize%>KB 
     <form name="myform" method="post" action="upload.asp?t=1&tMode=<%=tMode%>&re=<%=re%>&ubb=<%=ubb%>&isphoto=<%=isphoto%>" enctype="multipart/form-data">
	<INPUT TYPE="hidden" NAME="UploadCode" value="<%=PostRanNum%>">
	<input type="hidden" name="act" value="upload">
	文件：<input type="file" name="uploadfile" style="width:180px">
	<span id="mup1"></span>
	<span id="mup2"></span>
	<span id="mup3"></span>
	<span id="mup4"></span>
	<span id="mup5"></span>
	
	<input type="hidden" name="fname">
	<br/><br />
	<input type="submit" name="Ok" value="上传相片" > 
	 <input type="button" value="增加上传个数" onClick="addf();">
     </form>
	</ul>
</body>
<script language="javascript">
var i=0;
function addf(){
	i=i+1;
	if (i<5){
	document.all["mup"+i].innerHTML='<br />文件：<input type="file" name="uploadfile'+i+'" style="width:200px"> <input type="button" value="删除" onclick=delm("'+i+'");>';
	}else{
	i=i-1
	alert("超过最多上传限制!")
	}

}
function delm(m){
	document.all["mup"+m].innerHTML='';
	i=i-1;
}
</script>
</html>
<%
end sub

Sub Upfile_Main()	
%>
<ul style="margin:0px;text-align: left;width:100%;"> 
<%
UploadFile
%>
</ul>
</body>
</html>
<%
End Sub

Sub UploadFile()
	'If Not oblog.ChkPost Then
	'	Exit Sub
	'End If
	Server.ScriptTimeOut=9999999
'	'-----------------------------------------------------------------------------
	Dim Upload,FilePath,FormName,File,F_FileName,F_Viewname
	dim DrawInfo
	upfiletype=replace(upfiletype,"|",",")
	if freesize<=onesize then onesize=freesize
	if onesize<0 then onesize=0 
	if  Request("tmode")="9" then onesize=50
	if upload_dir<>"" then
		FilePath=upload_dir
	else
		FilePath = oblog.l_udir&"/"&oblog.l_ufolder&"/upload"
	end if
	FilePath=CreatePath(FilePath)
	If oblog.CacheCompont(12)="1" Then
		DrawInfo = oblog.CacheCompont(13)
	ElseIf oblog.CacheCompont(12)="2" Then
		DrawInfo = oblog.CacheCompont(18)
	Else
		DrawInfo = ""
	End If
	If DrawInfo = "0" Then
		DrawInfo = ""
		oblog.CacheCompont(12) = 0
	End If
	Set Upload = New UpFile_Cls
		if isphoto=1 then
			Upload.UploadType			= 0										'设置上传组件类型
		else
			Upload.UploadType			= Cint(oblog.CacheCompont(11))			'设置上传组件类型
		end if
		Upload.UploadPath			= FilePath								'设置上传路径
		Upload.MaxSize				= Int(onesize)							'单位 KB
		Upload.InceptMaxFile		= 8										'每次上传文件个数上限
		Upload.InceptFileType		= upfiletype							'设置上传文件限制
		Upload.RName				= ""
		Upload.ChkSessionName		= "UploadCode"
		if clng(oblog.CacheCompont(12))=1 or clng(oblog.CacheCompont(12))=2 then
			Upload.PreviewType			= 1								'设置预览图片组件类型
		else
			Upload.PreviewType			= 999
		end if
		Upload.PreviewImageWidth	= 130										'设置预览图片宽度
		Upload.PreviewImageHeight	= 100										'设置预览图片高度
		Upload.DrawImageWidth		= oblog.CacheCompont(22)						'设置水印图片或文字区域宽度
		Upload.DrawImageHeight		= oblog.CacheCompont(21)						'设置水印图片或文字区域高度
		Upload.DrawGraph			= oblog.CacheCompont(19)						'设置水印透明度
		Upload.DrawFontColor		= oblog.CacheCompont(15)						'设置水印文字颜色
		Upload.DrawFontFamily		= oblog.CacheCompont(16)						'设置水印文字字体格式
		Upload.DrawFontSize			= oblog.CacheCompont(17)						'设置水印文字字体大小
		Upload.DrawFontBold			= oblog.CacheCompont(17)						'设置水印文字是否粗体
		Upload.DrawInfo				=  DrawInfo								'设置水印文字信息或图片信息
		Upload.DrawType				= oblog.CacheCompont(12)						'0=不加载水印 ，1=加载水印文字，2=加载水印图片
		Upload.DrawXYType			= oblog.CacheCompont(23)						'"0" =左上，"1"=左下,"2"=居中,"3"=右上,"4"=右下
		Upload.DrawSizeType			= 1										'"0"=固定缩小，"1"=等比例缩小
		If oblog.CacheCompont(21)<>"" or oblog.CacheCompont(20)<>"0" Then
			Upload.TransitionColor	= oblog.CacheCompont(20)			'透明度颜色设置
		End If

		'执行上传
		Upload.SaveUpFile
		If Upload.ErrCodes<>0 Then
			'oblog.BuildFile(Server.mappath("err.txt"),"888")
			Response.write "错误："& Upload.Description & "[ <a href='upload.asp?re="&re&"&ubb="&ubb&"&isphoto="&isphoto&"&tMode="& tMode &"'>重新上传</a> ]"
			Exit Sub
		End If
		If Upload.Count > 0 Then
			For Each FormName In Upload.UploadFiles
				Set File = Upload.UploadFiles(FormName)
				F_FileName = FilePath & File.FileName
				'创建预览及水印图片
				If Upload.PreviewType<>999 and File.FileType=1 then
						F_Viewname =  FilePath&"pre" & Replace(File.FileName,File.FileExt,"") & "jpg"
						'创建预览图片:Call CreateView(原始文件的路径,预览文件名及路径,原文件后缀)
						Upload.CreateView F_FileName,F_Viewname,File.FileExt
				End If
					if re<>"no" then
						select case file.filetype
						case 1
							If tMode="9" Then
								'头像
								Response.Write "<script>parent.oblogform.ico.value='" & F_FileName & "';parent.getImg();</script>"
							ElseIf tMode="10" Then
							Else
								If tMode="1" Then
									Response.Write "<script>parent.oblogform.log_pics.value+='" & F_FileName & "\n';</script>"								
								End if
								if ubb="1" then
									Response.Write "<script>parent.oblogform.ubbedit.value+='[IMG]"&F_FileName&"[/IMG]';</script>"
								else
									Response.Write "<script>parent.oblog_editors['edit'].setHTML(parent.oblog_editors['edit'].getHTML()+'<img src=""'+window.location.href.substring(0,window.location.href.lastIndexOf('/'))+'/"&F_FileName&"""/><br/>');</script>"
								end if
								if isphoto=2 then
									Response.Write "<script>parent.oblogform.face.value='"&F_FileName&"';</script>"
								end if
							End If
						case else
							If tMode<>"10" Then
								if ubb="1" then
									Response.Write "<script>parent.oblogform.ubbedit.value+='[UPLOAD="&blogdir&F_FileName&"]"&File.FileName&"[/UPLOAD]';</script>"
								else
									If tMode<>9 Then
										Response.Write "<script>parent.oblog_editors['edit'].setHTML(parent.oblog_editors['edit'].getHTML()+'<a href=""'+window.location.href.substring(0,window.location.href.lastIndexOf('/'))+'/"&F_FileName&""">" & F_FileName & "</a><br/>');</script>"
									End If
								end if
							End If
						end select
					else
						
					end if
					oblog.execute("update oblog_user set user_upfiles_num=user_upfiles_num+1,user_upfiles_size=user_upfiles_size+"&File.FileSize&" where userid="&oblog.l_uid)
					oblog.execute("Insert into oblog_upfile (userid,file_name,file_path,file_ext,file_size,isphoto,sysclassid,userclassid) values ("&oblog.l_uid&",'"&File.FileName&"','"&F_FileName&"','"&File.FileExt&"',"&File.FileSize&","&isphoto&","&sysclass&","&subject&")")
					Response.Write "文件："& F_FileName &"上传成功![ <a href=upload.asp?re="&re&"&ubb="&ubb&"&isphoto="&isphoto&"&tMode=" & tMode &">再次上传</a> ]"
				Set File = Nothing
			Next
		Else
			Response.write "请正确选择要上传的文件。[ <a href='upload.asp?re="&re&"&ubb="&ubb&"&isphoto="&isphoto&"&tMode=" & tMode &"'>重新上传</a> ]"
			Exit Sub
		End If
	Set Upload = Nothing
End Sub
'检查上传目录，若无目录则自动建立
Function CreatePath(PathValue)
	Dim objFSO,Fsofolder,uploadpath
	if upload_dir<>"" then
		uploadpath = year(Date) & "-" & month(Date)
	else
		uploadpath=""
	end if
	If Right(PathValue,1)<>"/" Then PathValue = PathValue&"/"
	On Error Resume Next
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	if upload_dir<>"" then '检查上传目录
		If objFSO.FolderExists(Server.MapPath(upload_dir))=False Then
			objFSO.CreateFolder Server.MapPath(upload_dir)
		End If
	end if
	If objFSO.FolderExists(Server.MapPath(PathValue & uploadpath))=False Then
		objFSO.CreateFolder Server.MapPath(PathValue & uploadpath)
	End If
	If Err.Number = 0 and upload_dir<>"" Then
		CreatePath = PathValue & uploadpath & "/"
	Else
		CreatePath = PathValue
	End If
	Set objFSO = Nothing
End Function
%>