<!--#include file="../conn.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="../inc/config.asp"-->
<!--#include file="../../include/Lebi_config.asp"-->
 <!--#include file="upfile_class.asp"-->
<%
Dim Path,ModeID,UpfilesSize
Draw_SizeType = 1
rem 读取水印内容
If Upload_isDraw = "1" Then
	DrawInfo = Upload_Drawtext
	ModeID = 1
ElseIf Upload_isDraw = "2" Then
	DrawInfo = "../.."& Upload_Drawpic
	ModeID = 1
Else
	DrawInfo = ""
	ModeID = 0
End If
If DrawInfo = "0" Then
	DrawInfo = ""
	Upload_isDraw = 0
End If
Path = "../../"& PicPath &"/"
UpfilesSize=5000
const UpFileType="jpg|gif|jpeg|png|swf"
dim upload,oFile,formName,SavePath,filename,fileExts,oFileSize
dim arrUpFileType
dim ranNum
dim msg,FoundErr
msg=""
FoundErr=false
EnableUpload=False
yy=year(Date()):mm=month(Date())
if len(mm)=1 then mm="0"&mm
folder_date=yy&mm
call upload_0()
sub upload_0()    '使用化境无组件上传类
	set upload=new upfile_class ''建立上传对象
	upload.GetData(104857600)   '取得上传数据,限制最大上传100M
 	if upload.err > 0 then  '如果出错
		select case upload.err
			case 1
				response.write "请先选择你要上传的文件！"
			case 2
				response.write "你上传的文件总大小超出了最大限制（100M）"
		end select
		response.end
	end if
	SavePath = CreatePath(Path)   '存放上传文件的目录
	if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
	for each formName in upload.file '列出所有上传了的文件
		set ofile=upload.file(formName)  '生成一个文件对象
		oFileSize=ofile.filesize
		if oFileSize<100 then
			response.Write("请先选择你要上传的文件！")
			FoundErr=True
		elseif CDbl(oFileSize) > CDbl(UpfilesSize*1024) then
 			response.Write("文件大小超过了限制，最大只能上传" & CStr(UpfilesSize) & "K的文件！")
			FoundErr=true
		end if
		fileExts=FixFileName(lcase(trim(ofile.fileExt)))
		if(instr(UpFileType,fileExts)=0) then
			response.Write("不允许上传的文件类型："&fileExts)
			FoundErr=True
			Exit Sub 
		end if
		if FoundErr<>true Then
			Select Case Upload_SaveType
			Case "0" 
					Randomize
					RanNum = Int(900*rnd)+100
					filename = Day(now) & Hour(now) & Minute(now) & Second(now) & RanNum & "." & FileExts
			Case "1"
					filename = ofile.filename
			End Select 
			If Upload_RName <> "" Then filename = Upload_RName & filename
			ofile.SaveToFile Server.mappath(SavePath&FileName)   '保存文件
			sData = LoadFile(SavePath&FileName)
			If Not SniffSafety(sData) Then
				set objfso = server.createobject("scripting.FileSystemObject")
				If objfso.FileExists(server.MapPath(SavePath&FileName)) then
						objfso.DeleteFile(server.MapPath(SavePath&FileName))
				End If
				Exit Sub
			End If
			If Upload_Dir = "1" Then folder_date = "product"
			Select Case ModeID
			Case "1" Image_Obj_1 SavePath&FileName,0,fileExts
			'Case "2" Image_Obj_1 SavePath&FileName,"../../"& PicPath &"/"& folder_date &"/s_"& FileName,fileExts
			End Select 
		    response.Write("@@"& folder_date &"_b/"& FileName &"")
		end if
		set file=nothing
	next
	set upload=Nothing
end Sub
Function CreatePath(PathValue)
	Dim objFSO,Fsofolder,uploadpath
	Select Case Upload_Dir 
	Case "0" 
		yy=year(Date()):mm=month(Date())
        if len(mm)=1 then mm="0"&mm
		uploadpath = yy&mm&"_b"
	Case "1"
		uploadpath = "product_b"
	End Select 
	If Right(PathValue,1)<>"/" Then PathValue = PathValue&"/"
	On Error Resume Next
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
		If objFSO.FolderExists(Server.MapPath(PathValue & uploadpath))=False Then
			objFSO.CreateFolder Server.MapPath(PathValue & uploadpath)
		End If
		If Err.Number = 0 Then
			CreatePath = PathValue & uploadpath & "/"
		End If
	Set objFSO = Nothing
End Function
Function SniffSafety( sData )
	Dim oRE
	Set oRE = New RegExp
	oRE.IgnoreCase = True
	oRE.Global  = True
	Dim aPatterns
	'修改aPatterns的值，即可修改需要检测的字符串，^_^
	aPatterns = Array(".(getfolder|createfolder|deletefolder|createdirectory|deletedirectory|saveas)","wscript.shell","script.encode","server.",".createobject","execute","activexobject","language=","request")
	Dim i
	For i = 0 to UBound( aPatterns )
	oRE.Pattern = aPatterns( i )
	If oRE.Test( sData ) Then
	SniffSafety = False
	Exit Function
	End If
	Next
	SniffSafety = True
End Function

Function LoadFile(strFile)
		On Error Resume Next
		Dim strTempPath,objFSO,objStm
		strTempPath = Server.MapPath(strFile)
		Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
		Set objStm = Server.CreateObject("ADODB.Stream")
			If objFso.FileExists(strTempPath) Then
				objStm.charset = "UTF-8"
				objStm.open
				objStm.LoadFromFile strTempPath
				LoadFile = objStm.ReadText
			End If
		Set objStm = Nothing
		Set objFSO = Nothing
		If Err Then
				Err.Clear
		End If
End Function
'缩略图不加水印 2006-6-6 by 56770.kingdge
'---------------------AspJpegV1.2---------------
Sub Image_Obj_1(Imagename,TempFilename,FileExt)
		Dim Draw_X,Draw_Y,Logobox
		Draw_X = 0
		Draw_Y = 0
		FileExt = Lcase(FileExt)
		Set ImageObj = Server.CreateObject("Persits.Jpeg")
		ImageObj.Open Trim(Server.MapPath(Imagename))
		If CDbl(ImageObj.OriginalWidth) < CDbl(Upload_SPicWidth) or CDbl(ImageObj.Originalheight) < CDbl(Upload_SPicHeight) Then
			TempFilename = ""
			Exit Sub
		Else
			If FileExt<>"swf" and Upload_isDraw >0 Then
					If ImageObj.Width > ImageObj.height Then
					ImageObj.Width = Upload_SPicWidth
					ImageObj.Height = ViewImage_Height(ImageObj.OriginalWidth,ImageObj.Originalheight,Upload_SPicWidth,Upload_SPicHeight)
				Else
					ImageObj.Width = ViewImage_Width(ImageObj.OriginalWidth,ImageObj.Originalheight,Upload_SPicWidth,Upload_SPicHeight)
					ImageObj.Height = Upload_SPicHeight
				End If
				ImageObj.Sharpen 1, 120
				ImageObj.Save Server.MapPath(TempFilename)		'// 生成预览文件

				ImageObj.Open Trim(Server.MapPath(Imagename))
				Draw_X = CLng(DrawImage_X(ImageObj.OriginalWidth,Upload_DrawWidth,2))
				Draw_Y = CLng(DrawImage_y(ImageObj.Originalheight,Upload_DrawHight,2))
				ImageObj.Interpolation=1   
				ImageObj.Quality=100   
				If Upload_isDraw=2 Then
					Set Logobox = Server.CreateObject("Persits.Jpeg")
					'*添加水印图片	添加时请关闭水印字体*
					'//读取添加的图片
					Logobox.Open Server.MapPath(DrawInfo)
					Logobox.Width = Upload_DrawWidth								'// 加入图片的原宽度
					Logobox.Height = Upload_DrawHight							'// 加入图片的原高度
					ImageObj.DrawImage Draw_X, Draw_Y, Logobox, Upload_DrawGraph,Replace(Upload_Drawpiccolor,"#","&h"),90	'// 加入图片的位置价坐标（添加水印图片）
					'ImageObj.Sharpen 1, 130
					ImageObj.Save Server.MapPath(Imagename)
					Set Logobox=Nothing
				ElseIf Upload_isDraw=1 Then
					'//关于修改字体及文字颜色的
					ImageObj.Canvas.Font.Color		= Replace(Upload_Drawcolor,"#","&h")	'// 文字的颜色
					ImageObj.Canvas.Font.Family		= Upload_Drawfont	'// 文字的字体
					ImageObj.Canvas.Font.Bold		= Upload_DrawFontBold
					ImageObj.Canvas.Font.Size		= Upload_Drawfontsize					'//字体大小
					' Draw frame: black, 2-pixel width
					ImageObj.Canvas.Print Draw_X, Draw_Y, DrawInfo	'// 加入文字的位置坐标
					ImageObj.Canvas.Pen.Color		= &H000000		'// 边框的颜色
					ImageObj.Canvas.Pen.Width		= 1				'// 边框的粗细
					ImageObj.Canvas.Brush.Solid	= False			'// 图片边框内是否填充颜色
					'ImageObj.Canvas.Bar 0, 0, ImageObj.Width, ImageObj.Height	'// 图片边框线的位置坐标
					ImageObj.Save Server.MapPath(Imagename)
				End If
			End If
		End If
End Sub
'比例或固定缩小
Function ViewImage_Width(Image_W,Image_H,xView_W,xView_H)
	If Draw_SizeType = "1" Then
		ViewImage_Width = Image_W * xView_H / Image_H
	Else
		ViewImage_Width = xView_W
	End If
End Function

Function ViewImage_Height(Image_W,Image_H,xView_W,xView_H)
	If Draw_SizeType = "1" Then
		ViewImage_Height = xView_W * Image_H / Image_W
	Else
		ViewImage_Height = xView_H
	End If
End Function
'SpaceVal X轴坐标边缘距离
Function DrawImage_X(xImage_W,xLogo_W,SpaceVal)
	Select Case Upload_DrawXYType
		Case "0" '左上
			DrawImage_X = SpaceVal
		Case "1" '左下
			DrawImage_X = SpaceVal
		Case "2" '居中
			DrawImage_X = (xImage_W - xLogo_W) / 2
		Case "3" '右上
			DrawImage_X = xImage_W - xLogo_W - SpaceVal
		Case "4" '右下
			DrawImage_X = xImage_W - xLogo_W - SpaceVal
		Case Else '不显示
			DrawImage_X = 0
	End Select
End Function

'SpaceVal Y轴坐标边缘距离
Function DrawImage_Y(yImage_H,yLogo_H,SpaceVal)
	Select Case Upload_DrawXYType
		Case "0" '左上
			DrawImage_Y = SpaceVal
		Case "1" '左下
			DrawImage_Y = yImage_H - yLogo_H - SpaceVal
		Case "2" '居中
			DrawImage_Y = (yImage_H - yLogo_H) / 2
		Case "3" '右上
			DrawImage_Y = SpaceVal
		Case "4" '右下
			DrawImage_Y = yImage_H - yLogo_H - SpaceVal
		Case Else '不显示
			DrawImage_Y = 0
	End Select
End Function

Function FixFileName(Byval FName)
	If IsEmpty(FName) Then Exit Function
	FixFileName = Lcase(Trim(FName))
	FixFileName = Replace(FixFileName,Chr(0),"")
	FixFileName = Replace(FixFileName,"..","")
	FixFileName = Replace(FixFileName,";","")
	FixFileName = Replace(FixFileName,"'","")
	FixFileName = Replace(FixFileName,"/","")
	FixFileName = Replace(FixFileName,"\","")
	FixFileName = Replace(FixFileName,"[","")
	FixFileName = Replace(FixFileName,"]","")
	FixFileName = Replace(FixFileName,"<","")
	FixFileName = Replace(FixFileName,">","")
End Function
 %>