<%
'乘风多用户计数器 Sql版
'作者QQ：178575
'作者EMail：yliangcf@163.com
'作者网站：http://www.qqcf.com
'详细简介：http://www.qqcf.com/cfcount.htm
'上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
'因为这些内容可能时常更新，就没有放在程序里，请自己上网站上查看
'有完整版本的演示
%>
<!--#include FILE="Conn.asp"-->
<!--#Include File="CF_MyFunCtion.asp"-->
<!--#include FILE="CF_UpFile_Class.asp"-->
<%If Request("Action")="" Then%>
<body style="margin:0px;font-size:12px;background-color:transparent">
<!--#include FILE="CF_Style.asp"-->

<script>
function uploadcheck()
{
 if ((document.form1.ImgClass.value)=="")
 {
  window.alert ('请选择图片分类');
  document.form1.ImgClass.focus();
  return false;
 }
return true;
}
</script>
<form name="form1" method="post" action="?Action=upsave" enctype="multipart/form-data"  onsubmit="javascript:return uploadcheck();">
<table>
<tr>
<td>
<input type=file name="img">
<input type=hidden name="UserType" value="<%=Request("UserType")%>">
<input type=hidden name="CheckCode" value="<%=Request("CheckCode")%>">
<select name="ImgClass">
<option value=''>请选择图片分类</option>
<%
Sql="Select * From CFCount_SetContent Where SetBClassFlag='AdminClass' And SetSClassFlag='AdminClass_ImgClass'"
Set Rs=Conn.Execute(Sql)
While Not Rs.Eof
 Response.write "<option value='"&Rs("SetFlag_2")&"'>"&Rs("SetDesc")&"</option>"
Rs.MoveNext
Wend
%>
</select>
<%
If CInt(Request("UserType"))=1 Then
 Response.write "<input type=checkbox name='fileshare' value='-1' checked>"
 Response.write "共享给别人"
End If
%>
<input type=submit name="submit" value="上传">

</td>
</tr>
</table></form>

<%End If%>


<%If Request("Action")="upsave" Then%>
<%
If Cint(GetMySet("CFCountAdminSet","AdminSet","UploadType"))=1 Then

 Const UpFileType="jpg|gif" '允许的上传文件类型
 MaxFileSize= GetMySet("CFCountAdminSet","AdminSet","UploadMaxSize") '允许的最大上传文件多少K
 FormName="img"'上传的表单名称

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

 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("FileName")=FileName_2
  rs("FileSizeNum")=FileSizeNum
  rs("ImgClass")=ImgClass
  rs.update  

  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('上传成功!');" & VbCrlf
  Response.Write "top.location.href = 'AdminUser_Manage.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&"' And UpLoadState=-1"
     Rs.Open Sql,Conn,3,2
	 
	 If Rs.Eof Then
	  Response.write "验证码有误或没有上传权限"
	  Response.End
	 End If
     UserName=Rs("UserName")
	 
	 FileName=Rs("UserName")&"-"& DateDiff("s","2000-1-1",Now)
	 FileName_2=FileName&"."&FileExt
	 FilePath="upload/"&FileName_2  
	 

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

     Set Rs=server.createobject("adodb.recordset")
     sql="select Top 1 * from CFCount_Upfile"
     rs.open sql,conn,3,2
     rs.addnew
     rs("UserName")=UserName
	 rs("FileName")=FileName_2
	 rs("FileSizeNum")=FileSizeNum
	 rs("ImgClass")=ImgClass
	 
	 If FileShare=0 Then'不共享时
 	  rs("FileState")=-1
	  rs("FileShare")=0
	 Else
	  rs("FileState")=0
	  rs("FileShare")=-1
	 End If
	 
     rs.update
	 Rs.Close
    
 
  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('上传成功!');" & VbCrlf
  Response.Write "top.location.href = 'User_Manage.asp?Action=imglist&Assort=1';" & vbCrlf
  Response.Write "</script>" & VbCRLF
 End If

End If



If Cint(GetMySet("CFCountAdminSet","AdminSet","UploadType"))=2 Then
 Dim Count
 on Error Resume Next
 Set Upload = Server.CreateObject("Persits.Upload") 
 Upload.OverwriteFiles = False   '不能复盖
 Upload.IgnoreNoPost = True
 Upload.SetMaxSize GetMySet("CFCountAdminSet","AdminSet","UploadMaxSize")*1024, True	 '限制大小
 
 Count = Upload.Save
 
 If Err.Number = 8 Then 
  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('上传的文件大小超过限制！');" & VbCrlf
  Response.Write "history.go(-1);" & vbCrlf
  Response.Write "</script>" & VbCRLF
 Else 

  If Err <> 0 Then 
   Response.Write "错误信息: " & Err.Description 
  Else
   If Count < 1 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
   For Each file in Upload.Files	'列出所有上传文件
	FileExt = Replace(File.ext,".","")
	FileSizeNum=File.Size
	
    If  CheckFileExt(FileExt)=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
    '文件变量付值
	
 '表单内容在Upload.Save及Err后执行才有效
 UserType = CInt(Upload.form("UserType"))
 ImgClass = CInt(Upload.form("ImgClass"))
 CheckCode = Replace(Upload.form("CheckCode"),"'","''")'过滤单引号
 FileShare= CInt(Upload.form("FileShare"))
 
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 

  
	 File.saveas Server.MapPath(FilePath)	'上传保存文件
 
	 Set Rs=server.createobject("adodb.recordset")
	 Sql="Select Top 1 * From CFCount_Upfile"
	 rs.open sql,conn,3,2
	 rs.addnew
	 rs("FileName")=FileName_2
	 rs("FileSizeNum")=FileSizeNum
	 rs("ImgClass")=ImgClass
	 rs.update  

	 Response.Write "<script language='javascript'>" & VbCRlf
	 Response.Write "alert('上传成功!');" & VbCrlf
	 Response.Write "top.location.href = 'AdminUser_Manage.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&"' And UpLoadState=-1"
     Rs.Open Sql,Conn,3,2
	 
	 If Rs.Eof Then
	  Response.write "验证码有误或没有上传权限"
	  Response.End
	 End If
     UserName=Rs("UserName")
	 
	 FileName=Rs("UserName")&"-"& DateDiff("s","2000-1-1",Now)
	 FileName_2=FileName&"."&FileExt
	 FilePath="upload/"&FileName_2
	 
     File.saveas Server.MapPath(FilePath)	'上传保存文件
	 
     Rs.Update
	 Rs.Close

     Set Rs=server.createobject("adodb.recordset")
     sql="select Top 1 * from CFCount_Upfile"
     rs.open sql,conn,3,2
     rs.addnew
     rs("UserName")=UserName
	 rs("FileName")=FileName_2
	 rs("FileSizeNum")=FileSizeNum
	 rs("ImgClass")=ImgClass
	 
	 If FileShare=0 Then'不共享时
 	  rs("FileState")=-1
	  rs("FileShare")=0
	 Else
	  rs("FileState")=0
	  rs("FileShare")=-1
	 End If
	 
     rs.update
	 Rs.Close
    
 
  Response.Write "<script language='javascript'>" & VbCRlf
  Response.Write "alert('上传成功!');" & VbCrlf
  Response.Write "top.location.href = 'User_Manage.asp?Action=imglist&Assort=1';" & vbCrlf
  Response.Write "</script>" & VbCRLF
 End If

	 

 
   Next
  End If 
 End If
 Set Upload =Nothing
End If


Function FixName(UpFileExt)
	If IsEmpty(UpFileExt) Then Exit Function
	FixName = Lcase(UpFileExt)
	FixName = Replace(FixName,Chr(0),"")
	FixName = Replace(FixName,".","")
	FixName = Replace(FixName,"asp","")
	FixName = Replace(FixName,"asa","")
	FixName = Replace(FixName,"aspx","")
	FixName = Replace(FixName,"cer","")
	FixName = Replace(FixName,"cdx","")
	FixName = Replace(FixName,"htr","")
End Function

Function CheckFileExt(FileExt)
	Dim ForumUpload,i
	ForumUpload="jpg,gif,swf"
	ForumUpload=Split(ForumUpload,",")
	CheckFileExt=False
	For i=0 to UBound(ForumUpload)
		If LCase(FileExt)=Lcase(Trim(ForumUpload(i))) Then
			CheckFileExt=True
			Exit Function
		End If
	Next
End Function

%>
<%End If%>