<!--#include file="MVC_DIRpopasp.asp"-->
<%
'上传文件，由P_("auto").upload( Array(字段名,上传文件允许的后缀名) )自动生成

POP_MVC.mvc_dir = "MVC_DIR"
POP_MVC.appPath = "APP_PATH"
POP_MVC.run


POP_MVC.config("TMPL_ACTION_SUCCESS") = POP_MVC.mvc_dir & "Tpl/dispatch_jump.ajax.html"
POP_MVC.config("TMPL_ACTION_ERROR") = POP_MVC.mvc_dir & "Tpl/dispatch_jump.ajax.html"
'如果非同源访问，关闭浏览器窗口
If Not POP_MVC.import("POPASP_CONTROLLER").isSelfOrigin Then
	POP_MVC.import("POPASP_CONTROLLER").error( Array("非法操作" ,"window.close" ,7 ) )
End If

'定义token键名与token值变量
Dim token_key,token_value,input_name,input_index

input_name = POP_MVC.get("input_name")

input_index = POP_MVC.get("input_index")

'如果无token访问，关闭浏览器窗口
If input_name = "" Then
	POP_MVC.import("POPASP_CONTROLLER").error( Array("非法操作" , "window.close" ,7 ) )
End If

If Not POP_MVC.String.reg_test( input_index,"^\d+$" ,"" ) Then
	POP_MVC.import("POPASP_CONTROLLER").error( Array("非法操作" , "window.close" ,7 ) )
End If

'键名就是入口文件名
token_key = POP_MVC.get("token_key")

'token值从cookie中获取
token_value = POP_MVC.get("token_value")

If session(token_key & "_" & token_value ) <> token_value Then
	POP_MVC.import("POPASP_CONTROLLER").error( Array("过期访问，重新上传" , "window.close" ,7 ) )
End If

POP_MVC.config("SHOW_PAGE_TRACE") = 0
%>
<script type="text/javascript">
	function a(path) {
		//这里的img_path必须与form表单中的一致
		window.opener.document.getElementsByName("<%=input_name%>")[<%=input_index%>].focus();
		window.opener.document.getElementsByName("<%=input_name%>")[<%=input_index%>].value = path;
		window.opener.document.getElementsByName("<%=input_name%>")[<%=input_index%>].style.width = window.opener.document.getElementsByName("<%=input_name%>")[<%=input_index%>].value.length * 9 + "px";
		window.opener.document.getElementsByName("<%=input_name%>")[<%=input_index%>].blur();
	}
</script>
<%
	if POP_MVC.isPost then
		dim filename
		
		'允许的文件类型在这里，多个用;分隔
		POP_MVC.config("UPLOAD_ALLOW_TYPES") = "UPLOAD_TYPES"
		
		filename = POP_MVC.upload( "upfile" )

		if filename <> "" then
			response.write "<script>a('"& filename &"');</script>"
			POP_MVC.import("POPASP_CONTROLLER").success( Array("<small>上传成功</small>" , "window.close" , 1 ) )
		else
			response.write "<script>alert('文件上传失败:" & POP_MVC.Uploader.description & "');window.close();</script>"	
		end if
	else
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>文件上传</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="?<%=QUERY__%>">
	<input type="file" name="upfile" />
	<input type="submit" value="上 传 " />
</form>
</body>
</html>
<%
	end if
%>