<!--#include file="upfile_class.asp"-->
<%
const upload_type=0   '上传方法：0=无惧无组件上传类，1=FSO上传 2=lyfupload，3=aspupload，4=chinaaspupload

const UpFileType_soft="rar|zip"
const UpFileType_pic="jpg|gif|bmp|png"
const UpFileType_video="wmv|asf|avi|mpg|ram|rm"
const UpFileType_book="jar"
const UpFileType_game="rar|zip"


const MaxFileSize=300

dim upload,oFile,formName,SavePath,filename,fileExt,oFileSize
dim EnableUpload
dim UpFileType,arrUpFileType
dim ranNum
dim msg,FoundErr
dim DialogType
msg=""
FoundErr=false
EnableUpload=false
'SavePath = SaveUpFilesPath   '存放上传文件的目录
backform=trim(request.QueryString("back"))
SavePath = trim(request.QueryString("dir"))   '存放上传文件的目录
if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
%>
<html>
<head>
<title>上传文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="editor_dialog.css">
</head>
<body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0">
<%
		select case upload_type
			case 0
				call upload_0()  '使用化境无组件上传类
			case else
				'response.write "本系统未开放插件功能"
				'response.end
		end select
%>
</body>
</html>
<%
sub upload_0()    '使用化境无组件上传类
	set upload=new upfile_class ''建立上传对象
	upload.GetData(307200)   '取得上传数据,限制最大上传100M
	if upload.err > 0 then  '如果出错
		select case upload.err
			case 1
				response.write "请先选择你要上传的文件！<a href="""&request.ServerVariables("HTTP_REFERER")&""">返回</a>"
			case 2
				response.write "文件总大小超出了最大限制（300k）<a href="""&request.ServerVariables("HTTP_REFERER")&""">重新选择</a>"
		end select
		response.end
	end if
	DialogType=trim(upload.form("DialogType"))
	select case DialogType
	case "pic"
		UpFileType=UpFileType_pic
	case "soft"
		UpFileType=UpFileType_soft
	case "video"
		UpFileType=UpFileType_video
	case "book"
		UpFileType=UpFileType_book
	case "game"
		UpFileType=UpFileType_game
	case "photo"
		UpFileType=UpFileType_pic
	case else
		UpFileType=""
	end select
	for each formName in upload.file '列出所有上传了的文件
		set ofile=upload.file(formName)  '生成一个文件对象
		oFileSize=ofile.filesize
		if oFileSize<100 then
			msg="请先选择你要上传的文件！"
			FoundErr=True
		elseif ofilesize>(MaxFileSize*1024) then
 			msg="文件大小超过了限制，最大只能上传" & CStr(MaxFileSize) & "K的文件！"
			FoundErr=true
		end if

		fileExt=lcase(ofile.FileExt)
		arrUpFileType=split(UpFileType,"|")
		for i=0 to ubound(arrUpFileType)
			if fileEXT=trim(arrUpFileType(i)) then
				EnableUpload=true
				exit for
			end if
		next
		if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
			EnableUpload=false
		end if
		if EnableUpload=false then
			msg="这种文件类型不允许上传！\n\n只允许上传这几种文件类型：" & UpFileType
			FoundErr=true
		end if
		
		
		strJS="<SCRIPT language=javascript>" & vbcrlf
		if FoundErr<>true then
			randomize
			ranNum=int(900*rnd)+100
			filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum

			ofile.SaveToFile Server.mappath(SavePath&FileName&"."&fileExt)   '保存文件
			
			
			
			if DialogType="pic" or DialogType="photo" then
			
				'搞缩略图开始
				Dim Jpeg,Path
				Set Jpeg = Server.CreateObject("Persits.Jpeg")
				' 图片所在位置
				'Path = Server.MapPath("images") & "clock.jpg"
				Path=Server.MapPath(SavePath)&"\"&FileName&"."&fileExt
				
				
				' 打开
				Jpeg.Open Path
				
				' 设置缩略图大小（这里比例设定为50%）
				If Jpeg.OriginalWidth > Jpeg.OriginalHeight then
				
					If Jpeg.OriginalWidth / Jpeg.OriginalHeight > 1 then
					Jpeg.Width = 190
					Jpeg.Height = int((190/Jpeg.OriginalWidth)*Jpeg.OriginalHeight)
					
					elseif Jpeg.OriginalWidth / Jpeg.OriginalHeight < 1 then
					Jpeg.Width = 190
					Jpeg.Height= int((190/Jpeg.OriginalWidth)*Jpeg.Height)
					elseif Jpeg.OriginalWidth / Jpeg.OriginalHeight = 1 then
					Jpeg.Width = 190
					Jpeg.Height= 190
					end if
				
				else
					If Jpeg.OriginalHeight / Jpeg.OriginalWidth > 1 then
					Jpeg.Height = 190
					Jpeg.Width = int((190/Jpeg.OriginalHeight)*Jpeg.OriginalWidth)
					
					elseif Jpeg.OriginalHeight / Jpeg.OriginalWidth < 1 then
					Jpeg.Height = 190
					Jpeg.Width= int((190/Jpeg.OriginalHeight)*Jpeg.Width)
					elseif Jpeg.OriginalHeight / Jpeg.OriginalWidth  = 1 then
					Jpeg.Width = 190
					Jpeg.Height= 190
					end if
				end if
				
				' 保存缩略图到指定文件夹下

				Jpeg.Save Server.MapPath(SavePath)&"\"&FileName&"_s."&fileExt
				
				
				'搞水印图开始

				Set Photo = Server.CreateObject("Persits.Jpeg") 
				PhotoPath = Server.MapPath(SavePath)&"\"&FileName&"."&fileExt 
				Photo.Open PhotoPath 
				Set Logo = Server.CreateObject("Persits.Jpeg") 
				LogoPath = Server.MapPath("logo")&"\logo.gif" 
				Logo.Open LogoPath 
				
				Logo.Width = 126
				Logo.Height = Logo.Width * Logo.OriginalHeight / Logo.OriginalWidth 
				
				'图片大于300才打水印
				if Photo.OriginalWidth>300 and Photo.OriginalHeight>300 then
					Photo.DrawImage 0, 0,Logo,&HFFFFFF
				end if
				
				Photo.Save Server.MapPath(SavePath)&"\"&FileName&"_f."&fileExt
				Set Photo=nothing
				set Logo=nothing

			end if
			

			if DialogType="photo" then
				response.Write("上传成功！<a href=""Upload_Dialog.asp?dir=/Photo/UploadPhoto&DialogType=photo&back=PhotoUrl"">继续上传？</a>")
				strJS=strJS & "url='图片地址'+(parent.document.form.PhotoUrl.length+1)+'|"& SavePath & FileName&"_f."&fileExt & "';" & vbcrlf
				strJS=strJS & "parent.document.form.PhotoUrl.options[parent.document.form.PhotoUrl.length]=new Option(url,url);" & vbcrlf
			elseif DialogType="pic" then
				strJS=strJS & "parent.document.form."&backform&".value='"& SavePath & FileName&"_s."&fileExt & "';" & vbcrlf
				response.write ("上传成功！")
			else
				strJS=strJS & "parent.document.form."&backform&".value='"& SavePath & FileName&"."&fileExt & "';" & vbcrlf
				response.write ("上传成功！")
			end if

		else
			strJS=strJS & "alert('" & msg & "');" & vbcrlf
			strJS=strJS & "history.go(-1);" & vbcrlf
		end if
		strJS=strJS & "</script>" & vbcrlf
		response.write strJS
		
		set file=nothing
	next
	set upload=nothing
end sub

%>

