<!--#include file="sdcms_check.asp"-->
<%on error resume next%>
<!--#include file="../inc/upload.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传文件</title>
<style>
body{font-size:12px;margin:6px 0 0 0;padding:0;}
form,dl,dt{margin:0px;padding:0;list-style:none;}
dl{width:400px;}
dt input{margin-right:10px;width:180px;overflow:hidden;}
.border{font-size:12px;border:#ccc solid 1px;}
</style>
</head>
<body>
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
set sdcms=nothing
t=trim(request("t"))
select case t
case "1":t=1
case else:t=0
end select
go=Request.QueryString("go")
if go="" or not isnumeric(go) then
go=0
end if
If Request.QueryString("action")="upload" Then 
Set upload=new SDCMS_upload
filepath=sdcms_root&sdcms_upfiledir&"/"&replace(date(),"-","")&"/" '上传文件目录，需要加"/"
For each formName in upload.File
set file=upload.File(formName)
Dim o,txt,FileExt:FileExt=file.FileExt
'后缀黑名单目前23种
txt=Split("asp|aspx|jsp|asa|html|htm|js|vbs|exe|cer|cdx|htw|ida|idq|shtm|shtml|stm|printer|cgi|php|php4|cfm|htr","|")
For o=0 To UBound(txt)
If InStr(LCase(FileExt),txt(o))<>0 Then 
	echo "<script>alert('您上传的格式错误！');location.href='?go="&go&"&t="&t&"';</script>":Died
End if
Next 

Randomize
ranNum=int(90000*rnd)+10000
filename=filepath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&FileExt
'开始保存文件
If file.FileSize>0 Then
set sdcms_f=new sdcms_function
sdcms_f.Create_upfile(left(filepath,(len(filepath)-1)))
set sdcms_f=nothing
file.SaveToFile Server.mappath(filename)
'==================================================================================
sFile=server.mappath(filename)
set MyFile=CreateObject("Scripting.FileSystemObject")
set MyText=MyFile.OpenTextFile(sFile, 1) '读取文本文件
sTextAll=lcase(MyText.ReadAll)
MyText.close
'判断用户文件中的危险操作
sStr=".get"&"fol"&"der .cre"&"atefo"&"lder .del"&"etefol"&"der .cre"&"atedire"&"ctory .del"&"etedirec"&"tory .sa"&"veas wscr"&"ipt.sh"&"ell scr"&"ipt.en"&"code"
sNoString=split(sStr," ") 
for i=0 to ubound(sNoString)
	if instr(sTextAll,sNoString(i)) then
	set filedel=CreateObject ("Scripting.FileSystemObject")
	filedel.deletefile server.mappath(FileName)
	echo "请勿上传恶意文件":Died
end if
next   
'==================================================================================
'if t=0 then filename=right(filename,len(filename)-3)
echo "<script type='text/javascript'>"
select case go
case "0":echo "parent.upload('" &filename&"');"
case "1":echo "parent.document.getElementById('t11').value='"&filename&"';"
case "2":echo "parent.document.getElementById('t3').value='"&filename&"';"
case "3"
if sdcms_editor_type=0 then
	echo "parent.oEdit1.putHTML(parent.oEdit1.getHTMLBody()+'"
elseif sdcms_editor_type=1 then
	echo "parent.eWebEditor1.insertHTML('"
end if
   select case LCase(FileExt)
   case "gif","jpg","bmp","png":echo "<div align=""center""><img src="""&filename&"""/></div>"
   case "swf":echo "<div align=""center""><embed src="""&filename&""" width=""400"" height=""300""></embed></div>"
   case "flv":echo "<div align=""center""><EMBED src=/plug/flv.swf width=400 height=317 type=application/x-shockwave-flash flashvars=""xml=&#13;&#10;&#13;&#10;{vcastr}{channel}{item}{source}"&filename&"{/source}&#13;&#10;&#13;&#10;{/item}{/channel}{config}{controlPanelBgColor}52479{/controlPanelBgColor}{/config}{/vcastr}"" allowFullScreen=""true"" quality=""high"" wmode=""opaque""></div>"
   case else:echo "附件下载：<a href="""&filename&""" target=""_blank"">"&right(filename,len(filename)-len(filepath))&"</a>"
   end select
echo"');"
End select
echo "</script>"
echo "上传成功,<a href=""?go="&go&"&t="&t&""">继续上传</a>":Died
End if
Set file=Nothing 
next
Set upload=Nothing 
if err="-2147467259" then echo "上传文件超过服务器限制":err.Clear:Died
End if
%>
<dl>
<form name="form1" method="post" action="?go=<%=go%>&action=upload&t=<%=t%>" enctype="multipart/form-data">
	<dt><input class="border"  type="file" name="file1" /><button type="submit" class="border"/>上传</button></dt>
</form>
</dl>
</body>
</html>