<!--#include file="../Inc/conn.asp"-->
<!--#include file="Admin_check.asp"-->
<!--#include file="../Inc/UploadClass.asp"-->
<%
Dim AngelF,Up_Max,Action
Up_Max=10
Action=Lcase(Trim(Request("Action")))
AngelF_upfiletype="doc|xls|zip|rar|flv|ppt|pdf"
Select Case Action
	Case "add":Save_Upfile
	Case Else:Main
End Select
Sub Save_Upfile
	Dim i,Filename,formPath,Err_Link,File_Type
	Echo "<html>"
	Echo "<style type=""text/css""> "
	Echo "*{margin:0;padding:0;font-size:12px;background:#F2F9E8;}"
	Echo "</style>"
	Echo "<body>"
	Dim sUploadDir:sUploadDir=SitePath&SiteUp&"/" & Year(Now) & right("0" & Month(Now), 2) & "/"
	CreateFolder(sUploadDir)
	Set AngelF=New UpLoadClass
		AngelF.FileType=AngelF_upfiletype
		AngelF.SavePath=sUploadDir
		AngelF.MaxSize=999999
		AngelF.AutoSave=0
		AngelF.Open()
		For I=2 to Ubound(AngelF.FileItem)
			Filename=AngelF.SavePath&AngelF.Form(AngelF.FileItem(I))
			Err_Link="<a href=""Admin_FileUp.asp"">重新上传</a>"
			Select Case AngelF.Form(AngelF.FileItem(I)&"_Err")
				Case -1:Echo"没有文件上传,"&Err_Link:Died
				Case 1: Echo"文件过大，上传失败,"&Err_Link:Died
				Case 2: Echo"不允许被上传的文件,"&Err_Link:Died
				Case 3: Echo"文件过大，且不允许被上传而未被保存,"&Err_Link:Died
				Case 4:	Echo"文件保存失败,"&Err_Link:Died
			End Select
			
			Select Case Lcase(Right(Filename,3))
				Case "flv":File_Type=0
				Case Else:File_Type=1
			End Select
				Echo "<script>parent.KE.insertHtml('Content','"
				Select Case File_Type
				Case 0:Echo "[flv=480,360]"&Filename&"[/flv]<br>"
				Case Else:Echo "附件下载：<a href="""&Filename&""" Target=""_blank"">"&AngelF.Form(AngelF.FileItem(I))&"</a><br>"
				End Select
				Echo "');</script>"
		Next
		IF Len(Filename)=0 Then
			Echo "<a href=""Admin_FileUp.asp"">请先添加附件</a>"
		Else
			Echo "文件上传成功,<a href=""Admin_FileUp.asp"">继续上传</a>"
		End IF
	Set AngelF=Nothing
End Sub
Sub Main
%>
<html> 
<head> 
<title>Angel工作室多文件上传</title> 
<script type="text/javascript"> 
function MultiSelector(list_target, max) 
{ 
this.list_target = list_target; 
this.count = 0; 
this.id = 0; 
var o=parent.document.getElementById("UpLoadIframe");
if (max){this.max = max;}else{this.max = -1;} 
this.addElement = function(element) 
{ 
if (element.tagName == 'INPUT' && element.type == 'file') 
{ 
element.name = 'file_' + this.id++; 
element.multi_selector = this; 
element.onchange = function() 
{ 
var inputs = document.getElementsByTagName("input"); 
var count = 0; 
var total=inputs.length;
for(var i=0;i <inputs.length;i++) 
{ 
if (inputs[i].type == 'file') 
{ 
if(this.value==inputs[i].value) 
{ 
count++; 
} 
}
}
if(count>1) 
{ 
alert("该文件已存在！"); 
return false; 
} 
if(!this.value.IsPicture()) 
{ 
alert("不允许上传此类文件!允许的类型：<%=AngelF_upfiletype%>"); 
return false; 
} 

var new_element=document.createElement('input'); 
new_element.type='file'; 
new_element.size=1; 
new_element.className="addfile"; 
this.parentNode.insertBefore(new_element, this); 
this.multi_selector.addElement(new_element); 
this.multi_selector.addListRow(this); 
this.style.position ='absolute'; 
this.style.left='0px'; 
} 
if (this.max != -1 && this.count >= this.max-1) 
{ 
element.disabled = true; 
} 
this.count++; 
this.current_element = element; 
(o.style||o).height=(parseInt(this.count)*16)+'px';
} 
else 
{ 
alert('Error: not a file input element'); 
} 
} 
this.addListRow = function(element) 
{ 
var new_row = document.createElement('div'); 
new_row.className="divName"; 
var a = document.createElement("a"); a.title = "删除";a.innerHTML = "删除"; a.href = "javascript:void(0);";
new_row.element = element; 
a.onclick = function() 
{ 
this.parentNode.element.parentNode.removeChild(this.parentNode.element); 
this.parentNode.parentNode.removeChild(this.parentNode); 
this.parentNode.element.multi_selector.count--; 
(o.style||o).height=(parseInt(this.parentNode.element.multi_selector.count)*16)+'px';
this.parentNode.element.multi_selector.current_element.disabled = false; 

return false; 
} 
var filename = element.value.substring(element.value.lastIndexOf("\\")+1)+"　"; 
new_row.innerHTML = filename; 
new_row.appendChild(a); 
this.list_target.appendChild(new_row); 
} 
} 
String.prototype.IsPicture = function() 
{ 
<%
Dim jstype,js_type,i
jstype=""
js_type=Split(AngelF_upfiletype,"|")
For i=0 to ubound(js_type)
jstype=jstype&"."&Lcase(js_type(i))&"|"
Next
%>
var strFilter="<%=jstype%>" ;
if(this.indexOf(".")>-1) 
{ 
	var p = this.lastIndexOf("."); 
	var strPostfix=this.substring(p,this.length) + '|'; 
	strPostfix = strPostfix.toLowerCase(); 
	if(strFilter.indexOf(strPostfix)>-1) 
	{ 
		return true; 
	} 
} 
return false; 
}
</script> 

<style type="text/css"> 
*,body,form{margin:0;padding:0;font-size:12px;background:#F2F9E8;}
a:link,a:visited{color:#00F;}
a.addfile{display:block;float:left;height:20px;margin-top:-1px;position:relative;text-decoration:none;top:0pt;width:80px;cursor:pointer;}
a:hover.addfile{display:block;float:left;height:20px;margin-top:-1px;position:relative;text-decoration:none;top:0pt;width:80px;cursor:pointer;}
input.addfile{cursor:pointer;height:20px;position:absolute;margin:0px 0 0 -75px;width:1px;filter:alpha(opacity=0);opacity:0;}
.bnt{background:#fff;border:0;text-decoration:underline;color:#00f;}
#files_list div{clear:both;margin-top:2px;}
.divName{float:left;padding-left:5px;}
form span{color:#999;}
.input{position:absolute;margin:-4px 0 0 0;}
</style> 
</head> 
<body style="height:80px"> 
<form id="form1" method="post" action="?Action=add" enctype="multipart/form-data"> 
<a href="javascript:void(0);" title="点击添加附件,支持类型：<%=AngelF_upfiletype%>">添加<input id="my_file_element"  class="addfile" size="1" type="file" hideFocus /></a>　<a href="javascript:form1.submit()">上传</a>　一次最多上传 <%=Up_Max%> 个<span id="files_list"></span>
<script type="text/javascript"> 
var multi_selector = new MultiSelector(document.getElementById('files_list'),<%=Up_Max+1%>); 
multi_selector.addElement(document.getElementById('my_file_element')); 
</script>
</form>
<%End Sub%>
</body> 
</html>