<!--#include file="base.asp"-->
<!--#include file="../lib/class/eycms.upload_cut.asp"-->
<!--#include file="../lib/class/eycms.draw.asp"-->
<%
function isuplogin_my(t0,t1,t2)
	isuplogin_my=0
	if eycms.strlen(t0)=0 or eycms.strlen(t1)=0 then
		exit function
	end if
	dim data
	data=eycms.db.dbload(1,"adminid,adminname,adminpass,islock","ey_admin","adminname='"&t0&"'","")
	if ubound(data)<0 Then
		exit function
	else
		if md5(data(1,0)&data(2,0)&t2)<>t1 or data(3,0)=0 then
			exit function
		end if
	end if
	isuplogin_my=1
end Function

sub adddb(byval t0,byval t1,byval t2,byval t3,byval t4,byval t5,byval t6,byval t7,byval t8,byval t9,byval t10)
	eycms.db.insert "ey_attachment",array(array("classid",t9,0,0),array("cid",t8,0,0),array("filepath",t0,255,1),array("filename",t1,255,1),array("filesize",eycms.getnum(t2),255,1),array("oldname",t3,255,1),array("fileext",t4,50,1),array("ispic",eycms.is_pic("."&t4),1,0),array("createip",eycms.getip,255,1),array("createdate",t5,255,0),array("adminid",t6,0,0),array("userid",t7,0,0),array("zt",t10,0,0),array("fullname",t0&t1,0,1))
	if eycms.is_pic(t1)=1 Then
		If CLng(t9)<>0 then
			dim draw
			set draw=new eycms_draw
				draw.add t0&t1
			set draw=Nothing
		End if
	end if
end Sub

Dim Msg											'表示自定义的附加返回消息。
Dim Success : Success = "false"					'表示图片是否已上传成功。
Dim SavePath : SavePath = eycms.uploaddir("")	'保存在服务器的虚拟路径
Dim SourceUrl									'表示原始图片的保存地址。
DIM AvatarUrls									'表示所有头像图片的保存地址，多个之间使用英文的逗号“,”分隔。
Dim SuccessNum : SuccessNum = 0
Dim FileName : FileName = eycms.getrndfilename()
Dim cid, classid

On Error Resume Next
Dim Upload
Set Upload = new AnUpLoad
	Upload.Charset = "UTF-8"								'设置字符集
	Upload.Exe = "*.bmp;*.jpg;*.gif;*.png;"					'设置允许上传的文件类型
	Upload.SingleSize = eycms.getsys("upmaxsize") * 1024	'设置单个文件的最大上传限制，按字节计算，该处为2MB
	Upload.GetData()
	If Upload.ErrorID > 0 Then
		Msg = Upload.Description
	Else
		cid = eycms.getint(Upload.Forms("cid"),0)
		classid = eycms.getint(Upload.Forms("classid"),1)
		dim t0,t1,t2
		t0=eycms.enhtml(Upload.Forms("admin_name"))
		t1=Upload.Forms("loginbase")
		t2=Upload.Forms("loginkey")
		if isuplogin_my(t0,t1,t2)=0 then
			Msg = "登录失败，请退出重新登陆"
		Else
			Dim File
			Set File = Upload.Files("__source")
			If File.IsFile Then
				Dim SourceFileName : SourceFileName = File.LocalName
				Dim SourceExtendName : SourceExtendName = Split(SourceFileName, ".")(1)
				File.UserSetName = "source_" & FileName 
				File.Extend = SourceExtendName
				Dim InitParams : InitParams = Upload.Forms("__initParams")
				SourceUrl = SavePath & File.UserSetName & "." & File.Extend & InitParams
				If File.SaveToFile(SavePath, -1, True) Then
					SuccessNum = SuccessNum + 1
				Else
					Msg = "原图片保存失败，错误信息：" & File.Exception	
				End If
			End If
			Set File = Nothing
			
			Set File = Upload.Files("__avatar1")
			File.UserSetName = FileName
			File.Extend = "jpg"
			If File.SaveToFile(SavePath, -1, True) Then
				SuccessNum = SuccessNum + 1
				AvatarUrls = AvatarUrls & """" & SavePath & File.FileName & ""","
				adddb SavePath,File.FileName,Round(File.Size/1024),"avatar",File.Extend,sqltime,0,0,cid,classid,-1
			Else
				Msg = "头像保存失败，错误信息：" & File.Exception	
			End If
			Set File = Nothing
		End if
	End If
Set Upload = Nothing

If Err.Number <> 0 Then 
	eycms.errlog "上传文件：ey_upload_cut.asp<br>详情："&err.description,0
	Err.Clear
End If
If SuccessNum > 0 Then Success = "true"
If AvatarUrls <> "" Then AvatarUrls = Left(AvatarUrls, Len(AvatarUrls) - 1)
eycms.echo "{""success"":" &Success& ", ""msg"":""" &Msg& """, ""sourceUrl"":""" &SourceUrl& """, ""avatarUrls"":[" &AvatarUrls& "]}"
%>