<%@ codepage ="65001" %>
<%charset="utf-8"%>
<!-- #include file = "../mycartconn/conn.asp" -->
<!-- #Include File = "../up/Function.asp" -->
<!-- #Include File = "../up/upload_utf.inc" -->
<%
server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
if not mid(server_v1,8,len(server_v2))=server_v2 then
	Response.Write "<script language=JavaScript>{window.alert('系统错误，拒绝从非本服务器登陆!');window.history.go(-1);}</script>"
	response.end
end If

if instr(Request.ServerVariables("HTTP_REFERER"),"http://"&Request.ServerVariables("HOST") )<1 then 
	Response.Write "<script language=JavaScript>{window.alert('系统错误，拒绝从非本服务器登陆!');window.history.go(-1);}</script>"
	response.end
End If

If request.Cookies(my_url)("huiyuan")="" or request.Cookies(my_url)("hypwd")="" Then
	response.write "<script>alert(""请先登陆！"");self.location.href='/mymolihe.asp';</script>"
	response.end
End If

function MakedownName()
dim fname
Randomize
fname = now()
fname = replace(fname,"-","")
fname = replace(fname," ","") 
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
fname = int(fname) + int((100-1+1)*Rnd + 1)
MakedownName=fname
end function 

'生成文件夹子程序
sub add_myfso (wjj)
set myfso = Server.CreateObject("Scripting.FileSystemObject")
If myfso.FolderExists(server.MapPath(wjj))=False Then
	myfso.CreateFolder server.MapPath(wjj)
End If
set myfso=nothing
end sub

bh=year(date) & right("00"&month(date),2) & right("00"&day(date),2)
formPath="../tp/userface/face/"&bh
add_myfso(formPath)



  set upload=new upload_5xSoft

  set file=upload.file("file")

	if file.FileSize>0 then
		if file.filesize>500*1024 Then
			set upload=nothing 
			set file=Nothing
			
			response.write "<script>alert(""图片大小超过限制！"");self.location.href='/mymolihe.asp';</script>"
			response.end
		else
			upflag=false
			select case trim(LCase(right(file.FileName,4)))
			case ".gif"
				upflag=true
			case ".jpg"
				upflag=True
			case ".png"
				upflag=true
			case ".jpeg"
				upflag=true
			case else
				upflag=false
			end Select

			if int(instr(lcase(file.FileName),".asp"))>0 or int(instr(lcase(file.FileName),".asa"))>0 or int(instr(lcase(file.FileName),".aspx"))>0 then
				upflag=false
			end If

			if not upflag Then

				set upload=nothing 
				set file=Nothing
				response.write "<script>alert(""图片格式不正确！"");self.location.href='/mymolihe.asp';</script>"
				response.end
			Else
				oldFileName=file.FileName
				FileName=MakedownName()&"."&mid(file.FileName,InStrRev(file.FileName, ".")+1)
				file.SaveAs Server.mappath(formPath&"/"&FileName)

				FileSeverPath=Server.mappath(formPath&"/"&FileName)
				if HX_ScanFile(FileSeverPath) then
					CheckFile FileSeverPath,True 

					set upload=nothing 
					set file=Nothing
					response.write "<script>alert(""图片被疑为含有木马！"");self.location.href='/mymolihe.asp';</script>"
					response.end
				end If
				
				'缩图、水印
				ljj=FileSeverPath
				Set Jpeg = Server.CreateObject("Persits.Jpeg")
				Jpeg.Open (ljj)
				'开始变更所有文件扩展名为jpg
				xt=left(FileName,len(FileName)-4)
				xt=xt&".jpg"
				'结束文件名变更

				'开始判断哪边为长边，以长边进行缩放
				imgWidth=Jpeg.OriginalWidth
				imgHeight=Jpeg.OriginalHeight
				If imgWidth>100 or imgHeight>125 then
					if imgHeight>imgWidth then 
						Jpeg.Width=100
						Jpeg.Height=Jpeg.OriginalHeight/(Jpeg.OriginalWidth/100)
					end if
					if imgWidth>=imgHeight then 
						Jpeg.Height=125
						Jpeg.Width=Jpeg.OriginalWidth/(Jpeg.OriginalHeight/125)
					end if
					'结束判断

					x=CInt((Jpeg.Width-100)/2)
					y=CInt((Jpeg.Height-125)/2)
					x1=x+100
					y1=y+125
					Jpeg.Canvas.Brush.Color = &HFFFFFF
					Jpeg.Sharpen 1, 125   '锐利处理
					Jpeg.Crop x,y,x1,y1   '切割处理
					Jpeg.Save (Server.MapPath(formPath) & "\" & xt)

					xt="face/"&bh&"/"&xt
				Else
					xt="face/"&bh&"/"&FileName
				End if
				Set Jpeg = Nothing


				sql="select img from huiyuan where huiyuan='"&replace(Request.Cookies(my_url)("huiyuan"),"'","")&"'"
				Set rs= Server.CreateObject("ADODB.Recordset")
				rs.open sql,conn,1,1
				If Not (rs.bof And rs.eof) Then

					DefPic = rs("img")     '删除首图
					If LCase(DefPic)<>"face/mofahe.jpg" then
						Set fso = Server.CreateObject("Scripting.FileSystemObject")
						strRubbishFile=server.MapPath("/tp/userface/"&DefPic)
						if fso.FileExists(strRubbishFile) then
							fso.DeleteFile(strRubbishFile)
						end if
						set fso=Nothing
					End If
				End If
				rs.close
				Set rs=nothing
						
				conn.execute("update huiyuan set img='"&xt&"' where huiyuan='"&replace(Request.Cookies(my_url)("huiyuan"),"'","")&"'")
			end if
		end if
	end if
	set upload=nothing 
	set file=Nothing

response.redirect myurl&"/mymolihe.asp"
%>
