<!--#include file="conn.asp"-->
<!--#include file="inc/cook2.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="top.asp"-->
<!--#include FILE="update_class.asp"-->
<%
editname=request("editname")
sltname=request("sltname")
sltnamem=request("sltnamem")
filepath=request("filepath")
booksize=request("booksize")
getname=request("getname")

'================文件目录=================
set fso =server.CreateObject("Scripting.FileSystemObject")
If Fso.folderExists(server.mappath("../"&filepath&""))=false Then
Fso.Createfolder(server.mappath("../"&filepath&""))
end if
If Fso.folderExists(server.mappath("../"&filepath&"/"&year(now)&""))=false Then
Fso.Createfolder(server.mappath("../"&filepath&"/"&year(now)&""))
end if
If Fso.folderExists(server.mappath("../"&filepath&"/"&year(now)&"/"&month(now)&""))=false Then
Fso.Createfolder(server.mappath("../"&filepath&"/"&year(now)&"/"&month(now)&""))
end if
set fso =nothing

filepath_input=filepath&"/"&year(now)&"/"&month(now)
filepath="../"&filepath_input
'========================================

MaxSize=10240000
call upload_0()  '使用化境无组件上传类
%>

<%
sub upload_0()    '使用化境无组件上传类
	set upload=new upfile_class ''建立上传对象
	upload.GetData(MaxSize)   '取得上传数据,限制最大上传10M
	if upload.isErr > 0 then  '如果出错
		select case upload.isErr
			case 1
				response.write "请先选择你要上传的文件！"
			case 2
				response.write "你上传的文件总大小超出了最大限制（100M）"
		end select
		response.end
	end if
		
	for each formName in upload.file '列出所有上传了的文件
		set ofile=upload.file(formName)  '生成一个文件对象
		oFileSize=ofile.filesize
		if oFileSize<100 then
			msg="请先选择你要上传的文件！"
			FoundErr=True
		else
		    if oFileSize>(MaxSize) then
         	 msg="文件大小超过了限制，最大只能上传" & CStr(MaxSize) & "K的文件！"
			 FoundErr=true
		    end if
		end if

		fileExt=lcase(ofile.FileExt)
		arrUpFileType=split(upload.AllowExt,";")
		for i=0 to ubound(arrUpFileType)
			if fileEXT=trim(arrUpFileType(i)) then
				EnableUpload=true
				exit for
			end if
		next
		if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
			EnableUpload=false
		end if
		if EnableUpload=false then
			msg="这种文件类型不允许上传！\n\n只允许上传这几种文件类型：" & upload.AllowExt
			FoundErr=true
		end if
		
		
		strJS="<SCRIPT language=javascript>" & vbcrlf
		if FoundErr<>true then
		  	extension=upload.file("img").FileExt
			FileName=GetNewFileName() '获取文件名
			FileName_slt=FileName&"_thumb"
			FileName_sltm=FileName&"_thumbm"
            SaveFilename=upload.AutoSave("img",Server.mappath(filepath)+"\",FileName)
			
			response.write "<div style='height:24px; line-height:24px;'>文件上传成功！大小为：" & cstr(round(oFileSize/1024)) & "K</div>"

			
			if editname<>"" then strJS=strJS & "parent.document.myform."&editname&".value='"&filepath_input&"/"&FileName&"."&extension&"';" & vbcrlf
			if thumb_pic=1 then
			if sltname<>"" then strJS=strJS & "parent.document.myform."&sltname&".value='"&filepath_input&"/"&FileName_slt&"."&extension&"';" & vbcrlf
			'else
			'if sltname<>"" then strJS=strJS & "parent.document.myform."&sltname&".value='"&filepath_input&"/"&FileName&"."&extension&"';" & vbcrlf
			end if
			if thumbm_pic=1 then
			if sltnamem<>"" then strJS=strJS & "parent.document.myform."&sltnamem&".value='"&filepath_input&"/"&FileName_sltm&"."&extension&"';" & vbcrlf
			end if
			if booksize<>"" then strJS=strJS & "parent.document.myform."&booksize&".value='"&cstr(round(oFileSize/1024))&"';" & vbcrlf
		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

Public Function GetNewFileName()
    Dim y, m, d, h, mm, S, r
    Randomize
    y = Year(Now)
    m = Month(Now): If m < 10 Then m = "0" & m
    d = Day(Now): If d < 10 Then d = "0" & d
    h = Hour(Now): If h < 10 Then h = "0" & h
    mm = Minute(Now): If mm < 10 Then mm = "0" & mm
    S = Second(Now): If S < 10 Then S = "0" & S
    r = 0
    r = CInt(Rnd() * 1000)
    If r < 10 Then r = "00" & r
    If r < 100 And r >= 10 Then r = "0" & r
    GetNewFileName = "i_"&y & m & d &"_"& h & mm & S & r
End Function

%>