<!--#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"-->
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p02")
'''''''''''''''''''''''''''''''''''''''''''''''
dim act
act=request.QueryString("act")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
	font-size:9pt;
	background-color: #D4D0C8;
}
.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
const upload_type=0 
	current_time=now
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	current_M=chan_data(current_time)
	current_D=chan_day(current_time)
	folder_mon=server.mappath("../pic")&"/"&current_M  '今月的目录
	folder_day=server.mappath("../pic")&"/"&current_M&"/"&current_D  '今天的目录
	'创建本月文件夹
	If (fs.FolderExists(folder_mon)) Then		'今天的目录是否存在

	Else
		fs.CreateFolder(folder_mon)		'创建今天的目录
	End If
	'创建今天文件夹
	If (fs.FolderExists(folder_day)) Then		'今天的目录是否存在

	Else
		fs.CreateFolder(folder_day)		'创建今天的目录
	End If

	set fs=nothing
	'const SaveUpFilesPath2="../pic"
	SaveUpFilesPath2="../pic"&"/"&current_M&"/"&current_D
	'const UpFileType="jpg|gif|bmp|png|swf"
	const ForbidFileType="asp,aspx,htm,html,js,shtml,rar,zip,cer,cdx"
	const EnableUploadFile="Yes"
	const MaxFileSize=102400

	dim upload,oFile,formName,SavePath,filename,fileExts,oFileSize
	dim EnableUpload
	dim arrUpFileType
	dim ranNum
	dim msg,FoundErr
	dim PhotoUrlID
	msg=""
	FoundErr=false
	EnableUpload=false
call upload_0()  '使用化境无组件上传类
%>
<script language="javascript">
parent.ReturnValue('<%=current_M&"/"&current_D&"/"&filename %>');
</script>
<%
else
%>
<base target="_self">
<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="window.close();"></td>
          </tr>
        </table>
</form></td>
  </tr>
</table></fieldset>
<%
end if
%>
</body>
</html>
<%
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 = SaveUpFilesPath2   '存放上传文件的目录
	
	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
				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=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExts
		
			ofile.SaveToFile Server.mappath(SavePath&FileName)   '保存文件

			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()
%>