<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="upfile_class.asp"-->
<!--#include file="checklogin.asp"-->
<%
dim act
act=request.QueryString("act")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
BACKGROUND-COLOR: #D4D0C8;
font-size:9pt
}
.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 current_time,current_M,current_D,todayStr,current_Floler,imgSavePath,imgSaveFolder,SavePath,arrUpFileType,isEnableUpload
	dim msg,FoundErr,fileSize,PicDesc,filepre
	isEnableUpload=false
	FoundErr=false
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	current_time=now()
	current_M=chan_data(current_time)
	current_D=chan_day(current_time)
	todayStr=current_M&current_D
	current_Folder=server.mappath("../"&UpfilePath)&"\"&todayStr	
	'创建文件夹
	If (fs.FolderExists(current_Folder)) Then

	Else
		fs.CreateFolder(current_Folder)
	End If
	set fs=nothing
	imgSaveFolder=UpfilePath&"/"&todayStr
	
	set upload=new upfile_class ''建立上传对象
	upload.GetData(10240000)   '取得上传数据,限制最大上传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	
	if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
	
	PicDesc=upload.Form("PicDesc")
	response.Write(PicDesc)
	for each formName in upload.file '列出所有上传了的文件
		set ofile=upload.file(formName)  '生成一个文件对象
		If instr(oFile.FileType,"text")<>0 then
			response.write   "<script>alert('error！');</script>"   
			Response.End   
	  	end   if
		oFileSize=ofile.filesize
		if oFileSize>(MaxUpFileSize) then
 			msg="文件大小超过了限制，最大只能上传" & CStr(MaxUpFileSize/1024) & "k的文件！"
			FoundErr=true
		end if
		if oFileSize>0 then
			fileExts=lcase(trim(ofile.fileExt))		
			arrUpFileType=split(UpFileType,"|")
			for i=0 to ubound(arrUpFileType)
				if fileExts=trim(arrUpFileType(i)) then
					isEnableUpload=true
					fileExts=arrUpFileType(i)
					exit for
				end if
			next
			if isEnableUpload=false then
				msg="这种文件类型不允许上传！\n\n只允许上传这几种文件类型：" & UpFileType
				FoundErr=true
			end if	
			
			if FoundErr<>true then
				randomize
				ranNum=int(900*rnd)+100
				filepre=chan_file(current_time)&ranNum
				filename=filepre&"."&fileExts		
				ofile.SaveToFile current_Folder&"\"&FileName   '保存文件
				'缩略图
				'call CreateJumbnail(current_Folder&"\"&FileName,current_Folder&"\"&filepre&"_jumbnail."&fileExts,240)
				'水印
				'call CreateWaterMark(current_Folder&"\"&FileName,current_Folder&"\"&FileName)
				fileSize=cstr(round(oFileSize/1024)) & "K"
				'保存至库
				if(session("Totcms_MemberUpimg")<>"") then
					session("Totcms_MemberUpimg")=cint(session("Totcms_MemberUpimg"))+1
				else
					session("Totcms_MemberUpimg")=1
				end if
				response.Write("<script language=""javascript"">"&Chr(10))
				
				response.Write("document.write('<div style=""background-color:#ffffff; padding-top:5px; height:30px; padding-left:10px;"" align=""left"">成功上传照片！</div>');")
				response.Write("parent.ReturnValue('"&SiteUrl&"/"&imgSaveFolder&"/"&filepre&"."&fileExts&"');")
				response.Write("window.close()")
				response.Write("</script>"&Chr(10))
			else
				response.Write("<script language=""javascript"">"&Chr(10))
				response.Write("alert(""")
				response.Write(msg)
				response.Write(""");")
				response.Write("window.close();"&Chr(10)&"</script>")			
			end if		
			set ofile=nothing
		end if
		exit for
	next
	set upload=nothing	
else
	if(session("Totcms_MemberUpimg")<>"" and Cint(session("Totcms_MemberUpimg"))>MemberUpImgPerDay) then
		response.Write("<script>alert('超出上传图片数量限制!');window.close();</script>")
	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" 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 colspan="2"><hr align="center" width="92%" size="1" noshade></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="parent.winclose();"></td>
          </tr>
        </table>
</form></td>
  </tr>
</table></fieldset>
<%	
	end if
end if
%>
</body>
</html>

<%
call connclose()
%>