<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<!--#include file="upfile_class.asp"-->
<!--#include file="inc/function.asp"-->
<%
function CreateWaterMark(p_s,p_t)
	'Set Img = Server.CreateObject("Persits.Jpeg")
	'Img.Open server.MapPath("/images/mark.png")
	dim pfname
	pfname=p_s
	if(instr(pfname,".jpg")>0) then
	Set Jpeg = Server.CreateObject("Persits.Jpeg")
	Jpeg.Open p_s
	Jpeg.Canvas.DrawPng (Jpeg.Width-266-10), (Jpeg.Height-54-10), server.MapPath("/images/logo.png")
	Jpeg.Save p_t
	set Jpeg=nothing
	
	end if
end function

function CreateJumbnail(p_s,p_t,scale)
	dim rect_L
	On Error Resume Next
	Set Jpeg = Server.CreateObject("Persits.Jpeg")
	if err=0 then 
			'开始缩略图
			'Set Jpeg = Server.CreateObject("Persits.Jpeg")
			Jpeg.Open p_s
			' New width
			rect_L =scale
			If Jpeg.OriginalWidth > Jpeg.OriginalHeight Then
				Jpeg.Width = rect_L
				Jpeg.Height = Jpeg.OriginalHeight * rect_L / Jpeg.OriginalWidth
			Else
				 Jpeg.Height =rect_L
				 Jpeg.Width = Jpeg.OriginalWidth * rect_L / Jpeg.OriginalHeight
			End If
			Jpeg.Save p_t
			Set Jpeg = Nothing	
			'END缩略图		
	else
			response.write("<script>alert('不能使用水印组件:Asp Jpeg');</script>"&Chr(10))
	end if
end function
dim act
act=request.QueryString("act")
if(request.QueryString("thumbnail")<>"") then
	thumbnail=Cint(request.QueryString("thumbnail"))
else
	thumbnail=0
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
BACKGROUND-COLOR: #D4D0C8;
font-size:9pt
}
form{ margin:0px; padding:0px;}
.tx1 { height: 20px;font-size: 9pt; border: 1px solid; border-color: #000000; color: #0000FF}
-->
</style>
</head>
<body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0">
<%
if(act="do") then
	dim rootpath,current_time,current_M,current_D,folder_mon
	current_time=now
	rootpath=server.MapPath("/")
	current_M=chan_data(current_time)
	current_D=chan_day(current_time)
	folder_mon=rootpath&"\"&Imgsavedir&"\"&current_M&current_D '今月的目录
	call MakeDir(folder_mon)
	
	const ForbidFileType="asp,aspx,htm,html,js,shtml,rar,zip,cer,cdx"
	const EnableUploadFile="Yes"
	const MaxFileSize=102400
	
	call upload_0("/"&Imgsavedir&"/"&current_M&current_D&"/")

else
%>
<base target="_self">
<a id="reload" href="upimg.htm" style="display:none">reload...</a>
<fieldset><legend>上传图片</legend>
<table width="400"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><form action="?act=do&thumbnail=<%=thumbnail%>" method="post" enctype="multipart/form-data" name="form2" style="margin:0 0 0 0 ">
        <table width="400"  border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#D4D0C8">
          <tr bgcolor="#D4D0C8">
            <td width="18%" height="30"><div align="right">选择 ： </div></td>
            <td width="82%">
              <div align="left">
                <input name="FileName" type="file" id="FileName" size="30" maxlength="100">
                </div></td>
          </tr>
          <tr bgcolor="#D4D0C8">
            <td>&nbsp;</td>
            <td height="30"><input type="submit" name="Submit3" value="上  传" style="font-size:12px; ">
            <input type="button" name="Submit32" value="取  消" style="font-size:12px; " onClick="window.close();"></td>
          </tr>
        </table>
</form></td>
  </tr>
</table></fieldset>
<%
end if
%>
</body>
</html>
<%
sub upload_0(SaveFilePath)    '使用化境无组件上传类
	dim upload,oFile,formName,filename,fileExts,oFileSize,return_str
	dim EnableUpload
	dim arrUpFileType
	dim ranNum
	dim msg,FoundErr
	dim PhotoUrlID
	msg=""
	FoundErr=false
	EnableUpload=false
	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 =SaveFilePath   '存放上传文件的目录
	
	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
			msg="请先选择你要上传的文件！"
			FoundErr=True
		elseif oFileSize>(MaxFileSize*1024) then
 			msg="文件大小超过了限制，最大只能上传" & CStr(MaxFileSize) & "K的文件！"
			FoundErr=true
		end if

		fileExts=lcase(trim(ofile.fileExt))
		if(instr(ForbidFileType,fileExts)<>0) then
			response.Write("不允许上传的文件类型："&fileExts)
			EnableUpload=false
			response.End()
		end if
		arrUpFileType=split(UpFileType,"|")
		for i=0 to ubound(arrUpFileType)
			if fileExts=trim(arrUpFileType(i)) then
				EnableUpload=true
				fileExts=trim(arrUpFileType(i))
				exit for
			end if
		next
		if fileExts="exe" or fileExts="asa" or fileExts="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_pre=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
			FileName=filename_pre&"."&fileExts
			ofile.SaveToFile Server.mappath(SavePath&FileName)   '保存文件		
				
			response.Write("<script language=""javascript"" type=""text/javascript"">")
			'缩略图
			if(thumbnail=1) then
				call CreateJumbnail(Server.mappath(SavePath&FileName),Server.mappath(SavePath&filename_pre&"_v."&fileExts),240)
				call CreateWaterMark(Server.mappath(SavePath&FileName),Server.mappath(SavePath&FileName))
				response.Write("parent.ReturnValue('"&"/"&Imgsavedir&"/"&current_M&current_D&"/"&filename_pre&"_v."&fileExts&"');")				
			else
				response.Write("parent.ReturnValue('"&"/"&Imgsavedir&"/"&current_M&current_D&"/"&filename&"');")
			end if			
			
			response.Write("window.close();")
			response.Write("</script>")
			'response.write "图片上传成功！图片大小为：" & cstr(round(oFileSize/1024)) & "K"			
		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
%>
<%
call connclose()
%>