<%
'乘风多用户计数器
'作者QQ：178575
'作者EMail：yliangcf@163.com
'作者网站：http://www.qqcf.com
'详细简介：http://www.qqcf.com/cfcount.htm
'上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
'因为这些内容可能时常更新，没有放在程序里，请自己上网站上查看
%>
<!--#include FILE="Conn.asp"-->
<!--#Include File="Include/MyFunction.asp"-->
<!--#include FILE="Include/UpFile_Class.asp"-->
<%If Action="" Then%>
<%
UserType=ChkStr(Request("UserType"),2)
CheckCode=ChkStr(Request("CheckCode"),1)

If UserType="" Or CheckCode="" Then
 Response.write "缺少参数"
 Response.End
End If
%>
<body style="margin:0px;font-size:12px;background-color:transparent"> 
<form name="form1" method="post" action="?Action=upsave" enctype="multipart/form-data">
<input type=file name="img">
<input type=hidden name="UserType" value="<%=UserType%>">
<input type=hidden name="CheckCode" value="<%=CheckCode%>">
<input type=submit name="submit" value="上传">
</form>
<%End If%>

<%If Action="upsave" Then%>
<%
 Const UpFileType="jpg|gif" '允许的上传文件类型
 Const MaxFileSize="100" '允许的最大上传文件多少K
 FormName="img"'上传的表单名称

 If Right(SavePath,1)<>"/" Then SavePath=SavePath&"/" '在目录后加(/) 

 set upfile=new upfile_class ''建立上传对象
 upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;"	'设置上传类型的黑名单
 upfile.GetData (10240000)   '取得上传数据,限制最大上传10M
 UserType = CInt(upfile.form("UserType"))
 CheckCode = Replace(upfile.form("CheckCode"),"'","''")'过滤单引号


 Set File=UpFile.File(FormName)    
 If file.filesize<100 Then
  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('请先选择你要上传的文件！');" & VbCrlf
  Response.Write "history.go(-1);" & vbCrlf
  Response.Write "</script>" & VbCRLF
  Response.End
 End If
 If File.filesize>(MaxFileSize*1024) Then
  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('上传的文件大小超过限制！');" & VbCrlf
  Response.Write "history.go(-1);" & vbCrlf
  Response.Write "</script>" & VbCRLF
  Response.End
 End If
		
 FileExt=Lcase(File.FileExt)
 FileSizeNum=File.filesize
 ForumUpload=Split(UpFileType,"|")
 For I=0 To Ubound(ForumUpload)
  If fileEXT=Trim(Forumupload(i)) Then
   EnableUpload=True
   Exit For
  End If
 Next
 If FileExt="asp" Or FileExt="asa" or FileExt="aspx" Then EnableUpload=False
 If EnableUpload=False Then
  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('对不起,不支持这类文件上传!');" & VbCrlf
  Response.Write "history.go(-1);" & vbCrlf
  Response.Write "</script>" & VbCRLF
  Response.End
 End If	


 If UserType=0 Then'管理员上传时
  FileName="sys-img-"&DateDiff("s","2000-1-1",Now)
  FileName_2=FileName&"."&FileExt 
  FilePath="upload/"&FileName_2  

  If RsSet("AdminCode")<>CheckCode Then
   Response.write "验证码有误"
   Response.End
  End If


  UpFile.SaveToFile FormName,Server.MapPath(FilePath)
  Set UpFile=nothing
 
  set rs=server.createobject("adodb.recordset")
  sql="select Top 1 * from CFCount_Upfile"
  rs.open sql,conn,3,2
  rs.addnew
  rs("FileSizeNum")=FileSizeNum
  rs("FileName")=FileName_2
  rs.update  
  Rs.Close
  
  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('上传成功!');" & VbCrlf
  Response.Write "top.location.href = 'AdminUser.asp?Action=imglist';" & vbCrlf
  Response.Write "</script>" & VbCRLF  
 ElseIf UserType=1 Then
     Set Rs=Server.CreateObject("Adodb.RecordSet")
     Sql="Select * From CFCount_User where UserCode='"&CheckCode&"'"
     Rs.Open Sql,Conn,3,2
	 
	 If Rs.Eof Then
	  Response.write "验证码有误或没有上传权限"
	  Response.End
	 End If
     
	 UserName=Rs("UserName")
	 FileName_2=UserName&"."&FileExt
	 FilePath="upload/"&FileName_2  

    
     UpFile.SaveToFile FormName,Server.MapPath(FilePath)
     Set UpFile=nothing
	 
     Rs("ImgFileName")=FileName_2
     Rs.Update
	 Rs.Close

  set rs=server.createobject("adodb.recordset")
  sql="select Top 1 * from CFCount_Upfile Where UserName='"&UserName&"'"
  rs.open sql,conn,3,2
  If Rs.Eof Then
   Rs.AddNew
   Rs("UserName")=UserName
  End If

  rs("FileSizeNum")=FileSizeNum
  rs("FileName")=FileName_2
  rs("AddTime")=Now()
  rs.update  
  Rs.Close
 
  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('上传成功!');" & VbCrlf
  Response.Write "top.location.href = 'User.asp?Action=imglist';" & vbCrlf
  Response.Write "</script>" & VbCRLF
 End If
%>
<%End If%>