<!-- #include file="include/skin.asp" -->
<!-- #include file="include/upload_config.asp" -->
<!-- #include file="include/jk_convert.asp" -->
<!-- #include file="include/jk_enurl.asp" -->
<!-- #include file="include/jk_msort.asp" -->
<!-- #include file="include/jk_val_code.asp" -->
<%
dim formname,upload_path,upload_type,upload_size,upload_mn,upload_mode,up_sort,up_valcode
dim session_for,go_back
session_for=joekoe_cms.web_cookies&"_admin_"
go_back="<a href='javascript:history.back(1)'>返回上一页</a>"
'--------------------------------------------------------------------------
Server.ScriptTimeOut=5000
'--------------------------------------------------------------------------
tit="文件上传"
is_refur_true=false
if session(session_for&"admin")="joekoe_admin" then
  call web_head(0,1,5,0,0)
  login_username=session(session_for&"admines")
  login_mode=format_power2(1,1)
else
  call web_head(2,1,5,0,0)   
end if
call msort_start(0)
call convert_load(login_mode)

function upsort_path(pvar)
  dim si
  upsort_path=true
  if pvar="face" then exit function
  upsort_path=msort_true(pvar)
end function
%>
</head>
<body topmargin=0 leftmargin=0>
<table border=0 height='100%' width='100%' cellspacing=0 cellpadding=0 class=bg>
<tr><td height='100%'>
<script language=javascript>
if (top.location==self.location) { top.location="./" }
</script>
<%
dim dim_upload,upload,up_text,up_path,uptemp,uppath,up_name,up_temp,upfile,upfilename,upfile_name,upfile_name2,upfilesize,upid,today_num,st,upcount
upcount=1
today_num=0
if var_null(login_username)="" and session(session_for&"admin")="" then
  response.write web_nologin
else
  dim_upload=split(web_dim(14),"|")
  upload_path=web_dim(13)
  upload_type=dim_upload(0)
  if instr(","&upload_type&",",",asp,")>1 then
    up_temp=","&upload_type&","
    up_temp=replace(up_temp,",asp,",",")
    upload_type=left(up_temp,len(up_temp)-1)
    upload_type=right(upload_type,len(upload_type)-1)
  end if
  upload_size=dim_upload(1)
  upload_mn=dim_upload(2)
  upload_mode=dim_upload(3)
  if not(isnumeric(upload_size)) then upload_size=0
  if not(isnumeric(upload_mn)) then upload_mn=1
  upload_mn=format_convert(upload_mn,"+")
  if not isnumeric(upload_mode) then upload_mode=0
  if upload_nums()=true then
    select case action
    case "upfile"
      if joekoe_cms.post_chk()=false then
        response.write web_nopost
      else
        call upload_way()
        response.write uptemp
      end if
    case else
      call upload_main()
    end select
  end if
  erase dim_upload
end if

call msort_end()
call web_clear(0)
%>
</td></tr>
</table>
</body>
</html>
<%
sub upload_0()	'无组件上传
  up_name=trim(upload.form("up_name"))
  up_text=trim(upload.form("up_text"))
  up_path=trim(upload.form("up_path"))
  up_temp=trim(upload.form("up_temp"))
  up_valcode=trim(upload.form("valcode"))
  call upload_val_par()
  if not up_val_chk(uppath) then
    call upload_msg(6)
    set upfile=nothing
    exit sub
  end if
  set upfile=upload.file("file_name1")
  upfilesize=upfile.filesize
  if upfilesize<=0 then
    call upload_msg(1)
    set upfile=nothing
    exit sub
  end if
  upfilename=upfile.fileName
  if upfilesize>(upload_size*1024) then
    call upload_msg(2)
    set upfile=nothing
    exit sub
  end if
  upfile_name=right(upfilename,(len(upfilename)-Instr(upfilename,".")))
  upfile_name=lcase(upfile_name)
  if instr(","&upload_type&",",","&upfile_name&",")<=0 then
    call upload_msg(3)
    set upfile=nothing
    exit sub
  end if
  upfile_name2=upfile_name
  upfile_name=up_name&"."&upfile_name
  upfile.saveas up_path&upfile_name
  call upload_data()
  call upload_msg(4)
  set upfile=nothing
end sub

sub upload_1()	'LyfUpload
  up_name=trim(upload.request("up_name"))
  up_text=trim(upload.request("up_text"))
  up_path=trim(upload.request("up_path"))
  up_temp=trim(upload.request("up_temp"))
  up_valcode=trim(upload.request("valcode"))
  if var_null(up_temp)="" then
    call upload_msg(1)
    exit sub
  end if
  upload.maxsize=upload_size*1024
  upload.extname=upload_type
  call upload_val_par()
  if not up_val_chk(uppath) then
    call upload_msg(6)
    set upfile=nothing
    exit sub
  end if
  upfile_name=apart_filename(up_temp,2,"\")
  upfile_name=lcase(upfile_name)
  if instr(","&upload_type&",",","&upfile_name&",")>0 then
    upfile_name2=upfile_name
    upfile_name=up_name&"."&upfile_name
  end if
  if right(up_path,1)="/" then up_path=left(up_path,len(up_path)-1)
  if right(up_path,1)<>"\" then up_path=up_path&"\"
  st=upload.savefile("file_name1",up_path,true,upfile_name)
  select case cstr(st)
  case "0"
    call upload_msg(2)
    exit sub
  case "1"
    call upload_msg(3)
    exit sub
  case "3"
    if session(session_for&"admin")<>"joekoe_admin" then
      call upload_msg(0)
      exit sub
    end if
    upfilesize=upload.filesize
  case ""
    call upload_msg(5)
    exit sub
  case else
    upfilesize=upload.filesize
  end select
  call upload_data()
  call upload_msg(4)
end sub

sub upload_2()	'Aspupload
  on error resume next
  if session(session_for&"admin")="joekoe_admin" or session(session_for&"uploadtype")="s" then
    upload.overwritefiles=true			'能复盖
  else
    upload.overwritefiles=false			'不能复盖
  end if
  upload.ignorenopost=true
  upload.setmaxSize upload_size*1024,true	'限制大小
  upcount=upload.save
  if err.number=8 then
    err.clear
    call upload_msg(2)
    exit sub
  end if
  if err<>0 then	'Err.Description
    call upload_msg(5)
    exit sub
  end if
  up_name=trim(upload.form("up_name"))
  up_text=trim(upload.form("up_text"))
  up_path=trim(upload.form("up_path"))
  up_temp=trim(upload.form("up_temp"))
  up_valcode=trim(upload.form("valcode"))
  call upload_val_par()
  if not up_val_chk(uppath) then
    call upload_msg(6)
    set upfile=nothing
    exit sub
  end if
  set upfile=upload.files("file_name1")
  if upcount<>1 then
    call upload_msg(1)
    set upfile=nothing
    exit sub
  end if
  upfilename=upfile.filename
  upfilesize=upfile.Size
  upfile_name=apart_filename(upfilename,2,".")
  upfile_name=lcase(upfile_name)
  if instr(","&upload_type&",",","&upfile_name&",")<=0 then
    call upload_msg(3)
    set upfile=nothing
    exit sub
  end if
  upfile_name2=upfile_name
  upfile_name=up_name&"."&upfile_name
  upfile.saveas up_path&upfile_name
  call upload_data()
  call upload_msg(4)
  set upfile=nothing
end sub

sub upload_val_par()
  up_name=var_null(up_name)
  if session(session_for&"admin")<>"joekoe_admin" and len(up_name)>2 and session(session_for&"uploadtype")<>"s" then up_name=""
  if len(up_name)<3 then up_name=up_name&joekoe_cms.rand_file("")
  if not upsort_path(up_path) then up_path="other"
  if len(up_path)<3 then up_path="other"
  uppath=up_path
  if uppath="face" then
    upload_type="gif"
    up_name="face_"&login_id
  end if
  if right(upload_path,1)<>"/" then upload_path=upload_path&"/"
  call upload_val_folder(upload_path,up_path)			'验证文件夹是否存在
  up_path=server.mappath(upload_path&up_path)
  if right(up_path,1)<>"/" then up_path=up_path&"/"
end sub

sub upload_data()
  dim uiid,unsort,utypes
  uiid=0
  unsort=""
  utypes=0
  sql="select id from upload where url='"&uppath&"/"&upfile_name&"'"
  if session(session_for&"uploadtype")="s" then
    uiid=int(login_id)
    unsort="uface"
    utypes=1
    sql="select id from upload where iid="&uiid&" and nsort='"&unsort&"'"
  end if
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    sql="insert into upload(iid,nsort,types,username,url,genre,sizes,tim) " & _
        "values("&uiid&",'"&unsort&"',"&utypes&",'"&login_username&"','"&uppath&"/"&upfile_name&"','"&upfile_name2&"',"&upfilesize&",'"&joekoe_cms.now_time&"')"
    call joekoe_cms.exec(sql,0)
    sql="select top 1 id from upload order by id desc"
    set rs=joekoe_cms.exec(sql,1)
    upid=int(rs("id"))
  else
    call joekoe_cms.exec("update upload set username='"&login_username&"',sizes="&upfilesize&",tim='"&joekoe_cms.now_time&"',url='"&uppath&"/"&upfile_name&"' where id="&rs("id"),0)
  end if
  rs.close
  session(session_for&"uploadtype")=""
end sub

function upload_nums()
  upload_nums=true
  if session(session_for&"admin")<>"joekoe_admin" then
    sql="select count(*) from upload where username='"&login_username&"' and tim>=#"&formatdatetime(formatdatetime(joekoe_cms.now_time,2))&"#"
    set rs=joekoe_cms.exec(sql,1)
    today_num=rs(0)
    rs.close
    if not(isnumeric(today_num)) then today_num=0
    if int(today_num)>=int(upload_mn) then
      upload_nums=false
      response.write "<font class=re>注意</font>：您今天已上传<font class=red>"&today_num&"</font>个文件，每天只能上传<font class=red>"&upload_mn&"</font>个文件。"
    end if
  end if
end function

sub upload_msg(mn)
  dim tmpjs
  select case mn
  case 0
    uptemp=vbcrlf&"<font class=red>上传失败</font>：参数出错！"&go_back
  case 1
    uptemp=vbcrlf&"<font class=red>上传失败</font>：您可能没有选择想要上传的文件！"&go_back
  case 2
    uptemp=vbcrlf&"<font class=red>上传失败</font>：文件太大！(不能超过<font class=red>"&int(upload_size)&"KB</font>) "&go_back
  case 3
    uptemp=vbcrlf&"<font class=red>上传失败</font>：文件类型只能为：<font class=blue>"&replace(upload_type,"|","、")&"</font> 等格式 "&go_back
  case 4
    uptemp=vbcrlf&"<font class=red>上传成功</font>：<a href='"&upload_path&uppath&"/"&upfile_name&"' target=_blank>"&upfile_name&"</a> ("&upfilesize&"Byte)"
    if instr(up_text,"pic")>0 then
      if uppath="face" then
        tmpjs=tmpjs&"parent.document.all."&up_text&".value='"&upload_path&uppath&"/"&upfile_name&"';"
        upid=0
      else
        tmpjs=tmpjs&"parent.document.all."&up_text&".value='"&uppath&"/"&upfile_name&"';"
      end if
    else
      uptemp=uptemp&vbcrlf&"&nbsp;&nbsp;[ <a href='?uppath="&uppath&"&upname=&uptext="&up_text&"'>点击继续上传</a> ]"
      tmpjs=tmpjs&"parent.document.all."&up_text&".value+='"
      select case lcase(upfile_name2)
      case "gif","jpg","bmp","png"
        tmpjs=tmpjs&"[IMG]"&upload_path&uppath&"/"&upfile_name&"[/IMG]"
      case "swf"
        tmpjs=tmpjs&"[FLASH=350,250]"&upload_path&uppath&"/"&upfile_name&"[/FLASH]"
      case else
        tmpjs=tmpjs&"[DOWNLOAD]"&upload_path&uppath&"/"&upfile_name&"[/DOWNLOAD]"
      end select
      tmpjs=tmpjs&"\n';"
    end if
    if int(upid)>0 then tmpjs=tmpjs&"parent.document.all.upid.value+=',"&upid&"';"
    if tmpjs<>"" then
      uptemp=uptemp&vbcrlf&"<script language=javascript>"&vbcrlf&tmpjs&vbcrlf&"</script>"
    end if
    call val_chk_end("up_"&uppath)
  case 5
    uptemp=vbcrlf&"<font class=red>上传失败</font>：未知错误！"&go_back
  case 6
    uptemp=vbcrlf&"<font class=red>上传失败</font>： <font class=red>验证码</font> 为空或有错误！"&go_back
  end select
end sub

sub upload_way()
  on error resume next
  dim up_way
  select case upload_mode
  case 0
    up_way="无"
    set upload=new upload_classes
  case 1
    up_way="LyfUpload"
    set upload=server.createobject("lyfupload.uploadfile")
  case 2
    up_way="AspUpload"
    set upload = server.createobject("persits.upload")
  end select
  if err then
    set upload=nothing
    err.clear
    response.write "空间不支持 <font class=red>"&up_way&" 组件</font> 上传！请后台配置后再进行上传功能。"
    exit sub
  end if
  
  select case upload_mode
  case 1
    call upload_1()
  case 2
    call upload_2()
  case else
    call upload_0()
  end select
  
  set upload=nothing
  if err then err.clear
end sub

sub upload_val_folder(uf_upload,uf_uppath)
  dim myfso,myfile,up_path
  set myfso=createobject("scripting.filesystemobject")
  if uf_uppath<>"" then
    myfile=server.mappath(uf_upload&uf_uppath)
    if not myfso.folderexists(myfile) then
      set up_path=myfso.createfolder(myfile)
    end if
  end if
  set myfso=nothing
end sub

sub upload_main()
  dim upname,uptext,cid
  session(session_for&"uploadtype")=""
  uppath=trim(request.querystring("uppath"))
  upname=trim(request.querystring("upname"))
  uptext=trim(request.querystring("uptext"))
  if session(session_for&"admin")<>"joekoe_admin" then
    if len(upname)>2 then upname=""
  end if
  if not upsort_path(uppath) then
    response.write "参数(1)出错！"
    exit sub
  end if
  if uppath="face" then
    session(session_for&"uploadtype")="s"
    if int(login_id)<1 then
      response.write "参数(2)出错！"
      exit sub
    end if
    upname="face_"&login_id
  end if
  if len(uppath)<1 or len(uptext)<1 then
    response.write "参数(3)出错！"
    exit sub
  end if
%>
<script language=javascript>
function frm_submit(theform)
{
  if (document.all||document.getElementById)
  {
    for (i=0;i<theform.length;i++)
    {
      var tempobj=theform.elements[i];
      if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
      tempobj.disabled=true;
    }
  }
}
</script>
<table border=0 cellspacing=0 cellpadding=2>
<form name=form1 action='?action=upfile' method=post enctype='multipart/form-data'<%if cstr(upload_mode)<>"0" then response.write " onsubmit=""javascript:frm_submit(this);"""%>>
<input type=hidden name=up_path value='<%response.write uppath%>'>
<input type=hidden name=up_name value='<% response.write upname %>'>
<input type=hidden name=up_text value='<% response.write uptext %>'>
<input type=hidden name=up_temp value=''>
<%response.write val_code_num("up_"&uppath,1)%>
<tr>
<td><input type=file name=file_name1 value='' size=10></td>
<td align=center height=30><%
  if uppath="face" then
    response.write "<input type=submit name=submit onclick=""up_temp.value=file_name1.value"" value='上 传'> <font class=blue>GIF</font> 格式，小于<font class=red>"&upload_size&"</font>KB"
  else
    response.write "<input type=submit name=submit onclick=""up_temp.value=file_name1.value"" value='点击上传'> (今天上传<font class=red>"&today_num&"</font>个,每天<font class=red>"&upload_mn&"</font>个,每个<font class=red>"&upload_size&"</font>KB)"
  end if
%></td>
</tr>
</form>
</table>
<%
end sub

function up_val_chk(vsort)
  if not val_is_true then
    up_val_chk=true
    exit function
  end if
  dim valcode,valc
  up_val_chk=false
  valcode="jk"&up_valcode
  valc=trim(request.cookies(joekoe_cms.web_cookies)("vc_up_"&vsort))
  if valcode<>"" and valcode<>"jk" and cstr(valcode)=cstr(valc) then
    up_val_chk=true
  end if
end function
%>