<!--#Include File="const.asp"-->
<!-- #include File="../inc/Cls_Upload.asp"-->
<%
dim ErrCodes,action,TempLateStr
action=trim(request("action"))
If Nslove.userid=0 Then
	Response.Redirect "/showerr.asp?ErrCodes="&Nslove.Other_Errs(3)&"@@@&action=login"
else
	if Nslove.iNs_Setting(69)="0" then
		Response.Redirect "/showerr.asp?ErrCodes="&Nslove.Other_Errs(13)&"@@@&action=stop"
	else
	Select Case action
		Case "upload"
			Call Upfile_Main()
	End Select
	if ErrCodes<>"" then Response.Redirect "/showerr.asp?ErrCodes="&ErrCodes&"@@@&action=myzone"
	Set Nslove=nothing
	end if
end if

Sub Upfile_Main()
	If Chkpost=false Then
		SendResults 1, "", "",Nslove.Other_Errs(1)
		Exit sub
	End If
	if Nslove.iGroupSetting(77)="0" then
		SendResults 1, "", "","您目前的等级不允许上传，请升级等级！"
		Exit sub
	end if
	Server.ScriptTimeOut=999999'要是你的空间支持上传的文件比较大，就必须设置。
	Dim FormName,FormPath,Filename,File_name,FileExt,Filesize,F_Type,rename
	Dim FilePath,ChildFilePath
	Dim Upload,File,F_FileName,InceptMaxFile
	Dim Previewpath,DrawInfo,F_Viewname,OnceUPCount
	Dim F_Filesize,F_FileExt,F_FileWidth,F_FileHeight
	OnceUPCount = Request.Cookies("OupNum")
	If OnceUPCount = "" or Not Isnumeric(OnceUPCount) Then
		OnceUPCount = 0
	Else
		OnceUPCount = Clng(OnceUPCount)
	End If
	If OnceUPCount >= Clng(Nslove.iGroupSetting(81)) then
 		SendResults 1, "", "","一次只能上传"&Nslove.iGroupSetting(81)&"个文件！"
		Exit Sub
	Else
		InceptMaxFile = Clng(Nslove.iGroupSetting(81)) - OnceUPCount
	End If
	If Not IsNumeric(Nslove.iUserToday(2)) Then Nslove.iUserToday(2) = 0
	If Clng(Nslove.iUserToday(2))>Clng(Nslove.iGroupSetting(80)) Then
 		SendResults 1, "", "","已超出了你每天上传的文件个数"&Nslove.iGroupSetting(80)&"个！"
		Exit Sub
	Else
		If Clng(Nslove.iGroupSetting(80))-Clng(Nslove.iUserToday(2))<InceptMaxFile Then
			InceptMaxFile = Clng(Nslove.iGroupSetting(80))-Clng(Nslove.iUserToday(2))
		End If
	End If
	FilePath = Create_Path(CheckFolder(4))	'上传目录路径
	FilePath = CreatePath(FilePath)''生成日期目录
	ChildFilePath = Replace(FilePath,Nslove.iNs_setting(29),"")'不带系统上传目录的下级目录路径
	Previewpath = Create_Path(CheckFolder(5))	'预览图片目录路径
	Previewpath = CreatePath(Previewpath)

	If Nslove.iNs_UploadSetting(9)="1" Then
		DrawInfo = Nslove.iNs_UploadSetting(4)
	ElseIf Nslove.iNs_UploadSetting(9)="2" Then
		DrawInfo = Nslove.iNs_UploadSetting(9)
	Else
		DrawInfo = ""
	End If
	If DrawInfo = "0" Then
		DrawInfo = ""
		Nslove.iNs_UploadSetting(9) = 0
	End If
	
	Set Upload = New UpFile_Cls						''建立上传对象
	Upload.UploadType=Cint(Nslove.iNs_UploadSetting(1))
	Upload.UploadPath=FilePath
	Upload.InceptFileType = replace(Nslove.iGroupSetting(78),"|",",")
	Upload.MaxSize= Cint(Nslove.iGroupSetting(79))
	Upload.InceptMaxFile		= InceptMaxFile	'每次上传文件个数上限
	Upload.ChkSessionName		= "GetCode"	'防止重复提交,SESSION名与提交的表单要一致。
	Upload.PreviewType			= Cint(Nslove.iNs_UploadSetting(2))	'设置预览图片组件类型
	Upload.PreviewImageWidth	= Nslove.iNs_UploadSetting(3)			'设置预览图片宽度
	Upload.PreviewImageHeight	= Nslove.iNs_UploadSetting(4)			'设置预览图片高度
	Upload.DrawImageWidth		= Nslove.iNs_UploadSetting(15)			'设置水印图片或文字区域宽度
	Upload.DrawImageHeight		= Nslove.iNs_UploadSetting(16)			'设置水印图片或文字区域高度
	Upload.DrawGraph			= Nslove.iNs_UploadSetting(13)			'设置水印透明度
	Upload.DrawFontColor		= Nslove.iNs_UploadSetting(9)			'设置水印文字颜色
	Upload.DrawFontFamily		= Nslove.iNs_UploadSetting(10)			'设置水印文字字体格式
	Upload.DrawFontSize			= Nslove.iNs_UploadSetting(8)			'设置水印文字字体大小
	Upload.DrawFontBold			= Nslove.iNs_UploadSetting(11)			'设置水印文字是否粗体
	Upload.DrawInfo				= DrawInfo								'设置水印文字信息或图片信息
	Upload.DrawType				= Nslove.iNs_UploadSetting(6)			'0=不加载水印 ，1=加载水印文字，2=加载水印图片
	Upload.DrawXYType			= Nslove.iNs_UploadSetting(17)			'"0" =左上，"1"=左下,"2"=居中,"3"=右上,"4"=右下
	Upload.DrawSizeType			= Nslove.iNs_UploadSetting(5)			'"0"=固定缩小，"1"=等比例缩小
	Upload.InceptForm			=0										'设置是否验证表单
	Upload.ChkInceptForm		=""					'设置验证表单名
	If Nslove.iNs_UploadSetting(14)<>"" or Nslove.iNs_UploadSetting(14)<>"0" Then''水印图片去除底色
		Upload.TransitionColor	= Nslove.iNs_UploadSetting(14)			'透明度颜色设置
	End If
	Upload.SaveUpFile()
	If Upload.ErrCodes<>0 Then
		SendResults 1,"", "",replace(Nslove.Other_Errs(20),"{$Title}",Upload.Description)
		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 = Previewpath & "pre" & Replace(File.FileName,File.FileExt,"") & "jpg"
						'创建预览图片:Call CreateView(原始文件的路径,预览文件名及路径,原文件后缀)
						Upload.CreateView F_FileName,F_Viewname,File.FileExt
				else
					F_Viewname=F_FileName
				End If
				
				UploadSave F_FileName,ChildFilePath&File.FileName,File.FileExt,File.FileSize,File.FileType,File.FileWidth,File.FileHeight,F_Viewname
			Set File = Nothing
		Next
	Else
		SendResults 1, "", "",Nslove.Other_Errs(21)
		Exit sub
	End If
Set Upload = Nothing
End sub

'保存上传数据并返回附件ID
Sub UploadSave(FileName,ChildFileName,FileExt,FileSize,F_Type,F_FileWidth,F_FileHeight,F_Viewname)
Dim ShowFileName,sFileUrl,upNum
	ChildFileName=Checkstr(ChildFileName)
	if F_Viewname="" then F_Viewname=ChildFileName
	ShowFileName=Checkstr(Replace(F_Viewname,Nslove.iNs_setting(29),""))
	sFileUrl=Nslove.iNs_setting(29)&ChildFileName
	Conn.Execute("insert into Ns_Upload(Userid,Username,UserPath,FilesName,FilesType,FilesSize,FilesWH,Viewname,Checked,AddTime) values ("&Nslove.UserID&",'"&trim(Nslove.iSession(5))&"','"&Nslove.iSession(22)&"','"&ChildFileName&"','"&FileExt&"',"&Filesize&",'"&F_FileWidth&"X"&F_FileHeight&"','"&ShowFileName&"',0,"&SqlNowString&")")
	upNum = Request.Cookies("OupNum")
	If upNum = "" or Not Isnumeric(upNum) Then
		upNum = 0
	Else
		upNum = Clng(upNum)
	End If
	Response.Cookies("OupNum") = upNum+1
	Dim iUserInfo,iToday
	iToday = Nslove.iUserToday(2)+1
	iUserInfo = Nslove.iUserToday(0) & "|" & Nslove.iUserToday(1) & "|" & iToday & "|" & Nslove.iUserToday(3)
	iUserInfo=Checkstr(iUserInfo)
	Conn.Execute("UPDATE [Ns_user] set UserToday = '" & iUserInfo &"' WHERE UserID = " & Nslove.UserID)
	Call CloseConn()
	Response.Redirect "user_suc.asp?action=editor&sFileUrl="&sFileUrl&"&FileName="&FileName&""
End sub
%>
