<!--#include file="../../Conn.asp"-->
<!--#include file="../../fy_inc/fy.Main.asp"-->
<!--#include file="../../fy_inc/UpLoadClass.asp"-->
<!--#include file="../../fy_inc/CreateView.asp"-->
 <% 	
	Dim fycms,UserID,G_UpFileType,G_UpfilesSize
	Set fycms = New ACT_Main
	Public Function UserLoginChecked()
	on error resume next
	Dim UserName,UserPassword
		UserLoginChecked = false 
		UserName = Rsql(fycms.toasc(fycms.s("fyuser")))
		UserPassword= Rsql(fycms.toasc(fycms.s("fypass")))
		IF UserName="" Or UserPassword = "" Then
		   UserLoginChecked=false
		   Exit Function
		Else
			Dim UserRs
			Set Userrs=fycms.Actexe("Select UserID,UserName,PassWord From User_fy Where UserName='" & UserName & "' And PassWord='" & UserPassword & "'")
			IF UserRS.Eof And UserRS.Bof Then
				UserLoginChecked=false
			Else
				UserLoginChecked = True
				UserID=userrs("UserID")
				GroupID = UserRS("GroupID")
				Dim Rs,GroupArr
				Set Rs=fycms.ACTEXE("Select ModeID,GroupSetting,GroupName from Group_fy  Where GroupID=" & GroupID & " order by GroupID desc")
				If Not Rs.Eof Then
					GroupArr=Split(Rs("GroupSetting"),"^@$@^")
					G_UpFileType=GroupArr(10)
					G_UpfilesSize=GroupArr(9)
				End If
 			End if
			UserRS.Close:Set UserRS=Nothing
	   End IF
	End Function 
	IF Cbool(UserLoginChecked)=false Then
		echo "<script>parent.ue_callback('','错误,未登录')</script>"
	  Response.end
	End If
 

 	 Dim Upload,FilePath,FormName,File,F_FileName,fs,instrs,myid,fp,TempFileName,fileext
  	fp="UpFiles/UserFile/"&UserID&"/scrawlUp/"&year(now) & "/" & month(now)& "/" & Day(now)&"/"
	Call fycms.CreateFolder(fycms.ActSys&fp)
	Select Case Request.QueryString("action")
		Case "tmpImg"
			Dim UpFile
			set UpFile = New UpLoadClass
			UpFile.AutoSave = 2
			UpFile.MaxSize =  G_UpfilesSize* 1024
			UpFile.FileType = G_UpFileType
			UpFile.SavePath = fycms.ActSys&fp
			UpFile.Open() '# 打开对象
			If UpFile.Save("upfile",0) Then
				F_FileName=fycms.ActSys&fp&UpFile.Form("upfile")
 				echo "<script>parent.ue_callback('" &F_FileName & "','SUCCESS')</script>"
 			  Else
				Select Case UpFile.Form("upfile_Err")
				Case -1 : echo "没有文件上传，请返回重新上传"
				Case 1 : echo "文件大小超出限制，请返回重新上传"
				Case 2 : echo "不允许上传的文件类型，请返回重新上传"
				Case 3 : echo "文件大小超出限制并且是不允许上传的文件类型，请返回重新上传</div>"
				Case Else : echo "未知错误，请返回重新上传</div>"
				End Select
			End If
			Set UpFile = Nothing
  	Case Else
 		FilePath=fycms.ActSys&fp&RandomFileName("jpg")
 		Call UnpackBase64(Request.Form("content"),FilePath)
		Response.Write "{'url':'" &FilePath& "',state:'SUCCESS'}"
 	
	End Select
  
  
  
  
  '利用XML对BASE64进行解压

Function UnpackBase64(Base64Code,savePath)
	Dim tmpXMLData
	tmpXMLData="<?xml version=""1.0"" encoding=""gb2312""?><file><stream xmlns:dt=""urn:schemas-microsoft-com:datatypes"" dt:dt=""bin.base64"">"&Base64Code&"</stream></file>"
	
	Dim objXmlFile
	Dim objNodeList
	Dim objStream
	Dim i, j
	Set objXmlFile = CreateObject("Microsoft.XMLDOM")
		objXmlFile.async = False
		objXmlFile.ValidateOnParse = False
			objXmlFile.LoadXML (tmpXMLData)
			If objXmlFile.readyState <> 4 Then
				response.write "error"
			Else
				If objXmlFile.parseError.errorCode <> 0 Then
					response.write "error"
				Else
					Set objNodeList = objXmlFile.documentElement.selectNodes("//file/stream")
							j = objNodeList.length - 1
							For i = 0 To j
								Set objStream = CreateObject("ADODB.Stream")
									With objStream
										.Type = 1
										.Open
										.Write objNodeList(i).nodeTypedvalue
 										.SaveToFile Server.MapPath(savePath), 2
										.Close
									End With
								Set objStream = Nothing
							Next
						Set objNodeList = Nothing
					End If
				End If
			Set objXmlFile = Nothing
		UnpackBase64=True
End Function

 '自动生成文件名
Function RandomFileName(Ext)
	Dim m_strDate,m_lngTime,dtmNow
	dtmNow=Date
	m_strDate = Year(dtmNow)&Right("0"&Month(dtmNow),2)&Right("0"&Day(dtmNow),2)
	m_lngTime = Clng(Timer()*1000)
	m_lngTime=m_lngTime+1
	RandomFileName=m_strDate&Right("00000000"&m_lngTime,8)&"."&ext
End Function
   %>
 