<!--#include file="up.asp"-->
<%

filepath="/upload/"		'上传路径
filepathname = "/upload/"
set upload=new clsUp		'建立上传对象
'upload.AllowExt=yxsclx		'设置上传类型
upload.NoAllowExt="asp;asa;cer;aspx;cs;vb;js;exe"		'设置上传类型的黑名单
upload.GetData (307200000)	'取得上传数据,限制最大上传3M

if upload.form("act")="uploadfile" then
yxsclx=upload.form("filelx")
filemax=upload.form("filemax")
filemax1=filemax*1024
	for each formName in upload.File
		set file=upload.File(formName)
		fileExt=lcase(file.FileExt)		'得到的文件扩展名不含有.
        if instr(yxsclx,fileExt)<=0 then Response.Write "<script language='javascript'>alert('上传的文件类型必须为"&yxsclx&"！');history.back();</script>":Response.end
			if file.filesize<10 then Response.Write "<script language='javascript'>alert('请选择要上传的文件！');history.back();</script>":Response.end
			if file.filesize>filemax1 then Response.Write "<script language='javascript'>alert('最大只能上传"&filemax&"K的文件！');history.back();</script>":Response.end
		dtNow=Now()
		randomize
		ranNum=int(90000*rnd)+10000
		filename1=year(dtNow) & right("0" & month(dtNow),2) & right("0" & day(dtNow),2) & right("0" & hour(dtNow),2) & right("0" & minute(dtNow),2) & right("0" & second(dtNow),2) & ranNum &"."&fileExt
		filename=filepath&filename1
		filelstname=filepathname&filename1
		
'		response.write ""&filelstname&"|"&file.FileSize&""
		
		if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
			upload.SaveToFile formName,Server.mappath(FileName)

			'这里可以存数据库
            if upload.form("EditName")="content" then
                       strJS="<SCRIPT language=javascript>" & vbcrlf
                       strJS=strJS & "content=window.opener.document.myform.content.value;" 
                       strJS=strJS &"content=content+'<a href=" & filelstname & " target=""_blank""><div align=""center""><img src=" &filelstname & "  border=""0""></div></a><br><br>';" & vbcrlf
                       'strJS=strJS &"content=content+'<a href=" & "../"&filelstname & " target=""_blank""><img src=" & "../"&filelstname & "  border=""0""></a><br><br>';" & vbcrlf
                       strJS=strJS & "window.opener.document.myform.content.value=content;" & vbcrlf
                      strJS=strJS & "</script>"
	  	      response.write strJS
	  	    else             
			response.write "<script>window.opener.document."&upload.form("FormName")&"."&upload.form("EditName")&".value='"&filelstname&"'</script>"
			end if
%>
			<script language="javascript">
				window.alert("文件上传成功！");
				window.close();
			</script>
			<%
		end if
		set file=nothing
	next
	set upload=nothing
end if
%>