📄 upfile.asp
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file = "admin/BBSConfig.asp"-->
<!--#include file="INC/upload.inc"-->
<!--#include file="INC/Board_Config.asp"-->
<%
response.Buffer = True
Server.ScriptTimeOut=5000
Dim server_v1,server_v2
server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(server_v1,8,len(server_v2))<>server_v2 then
response.Write("您提交的路径有误,请不要从本站以外的URL向本站提交数据")
response.End()
end if
'response.end
userid = trim(request.Cookies(JBBMasterCookies)("userid"))
styleid = trim(request.Cookies(JBBMasterCookies)("styleid"))
if userid = "" then
response.End
End if
set upload=new upload_5xsoft ''建立上传对象
uptype=upload.form("uptype")
if uptype<>"avatars" then
BoardID = upload.form("BoardID")
Board_info BoardID
Board_Config = Application(JBBMasterCookies&"Board_Config"&BoardID)
if Board_Config(6)=true then styleid = Board_Config(5)
End if
%>
<!--#include file="INC/style.asp"-->
<html>
<head>
<title>上传图片...</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script>
parent.document.forms[0].Submit.disabled=false;
parent.document.forms[0].Submit2.disabled=false;
</script>
<link href="<%=Css_path%>" rel="stylesheet" type="text/css">
</head>
<body leftmargin="0" topmargin="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="table-dark">
<%
dim upload,file,formName,formPath,iCount,times,fileExt,filename
if upload.form("filepath")="" then ''得到上传目录
HtmEnd "上传目录出错!"
set upload=nothing
response.end
else
formPath=upload.form("filepath")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
end if
formPath = Replace(formPath,".","")
SCRIPT_STRING = upload.form("SCRIPT_STRING")
iCount=0
for each formName in upload.objFile ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize=0 then ''如果 FileSize = 0 说明没有文件数据
response.write"请选择你要上传的文件![<a href=""javascript:history.back();"">重传</a>]"
resposne.End
set upload = Nothing
end if
'---------------------------格式化文件名------------------------
fileExt = formatFileName(file.FileName)
'response.Write(file.FileType)
'response.End()
'---------------------------是否为发贴上传-----------------------------
if trim(upload.form("uptype")) = "Board" then
'-------------------------------可上传文件大小------------------------------------
if file.FileSize > Board_Config(20) then
Htmend "您上传的文件太大,本版块只允许上传最大为 "& Board_Config(20) &" 字节的文件;"
set conn = nothing
set upload=nothing
response.End
End if
'--------------------------获取每天可上传数-------------------------------
upCount = trim(request.Cookies(""&date()&"")("upCount"))
if Not(IsNumeric(upCount)) then upCount = 0
response.Cookies(""&date()&"")("upCount") = upCount+1
response.cookies(""&date()&"").expires = dateadd("d", 7, date())
'--------------------------判断文件类别-------------------------------
UploadFileType = lcase(Board_Config(19))
If Not(CheckFileExt(UploadFileType,fileExt)) Or NotFileType(file.FileType) then
response.write"文件类别错误,[<a href=""javascript:history.back();"">重传</a>]"
set upload=nothing
response.End
End if
if IsNumeric(userid) then
set rs = Conn.ExeCute("select usergroup from JBB_user where userid="&userid)
if Not rs.Eof then
group = rs(0)
End if
set rs = nothing
End if
if Not(IsNumeric(group)) then group = 6
set rs = Conn.ExeCute("select upcount from JBB_usergroup where groupID = "&group)
if not rs.eof then
up_count = rs(0)
End if
set rs = nothing
set conn = nothing
if int(upcount) => int(up_count) then
response.Write("<font color=""#0000FF"">您今日不可以再上传文件</font>")
set upload=nothing
response.End()
End if
End if
'----------------------上传文件数结束---------------------------
if uptype = "avatars" then
if Right(fileEXT,3)<>"gif" and Right(fileEXT,3)<>"jpg" then
response.write"文件类别错误,头像只支持.jpg或.gif类型文件[<a href=""javascript:history.back();"">重传</a>]"
set upload=nothing
response.end
End if
filename = formPath&"user_"&userid&"."&formatFileName(Right("."&fileExt,3))
else
filename = formPath&fomrmatTime&"."&formatFileName("."&fileExt)
filename2 = file.FileName
End if
file.SaveAs Server.mappath(filename) ''保存文件
iCount=iCount+1
set file=nothing
next
if uptype = "avatars" then
response.write "<script>parent.myform.avatars2.value ='"& filename &"'</script>"
else
select case Right(fileEXT,3)
case "gif","jpg","bmp"
filelink = "[img]"& filename &"[/img]"
Case "swf"
filelink = "[flash]"& filename &"[/flash]"
Case else
filelink = "附件:[url="& filename &"]"& filename2 &"[/url]"
End select
response.write "<script>parent.myform.txtcontent.value +='"& filelink &"'</script>"
End if
set upload=nothing ''删除此对象
Htmend " 上传完毕! <a href="""&filename&""" target=""_blank"">查看</a>"
sub HtmEnd(Msg)
set upload=nothing
response.write Msg&" [<a href=""up.asp?"&SCRIPT_STRING &""">再上传</a>]"
response.end
end sub
'替换文件名中的非法字符
Function formatFileName(UpFileStr)
dim tem
tem = lcase(UpFileStr)
tem = replace(replace(tem,"\",""),"/","")
tem = replace(tem,"'","")
tem = replace(tem," ","")
tem = Replace(tem,Chr(0),"")
tem = Replace(tem,".asp","")
tem = Replace(tem,"asp","")
tem = Replace(tem,"asa","")
tem = Replace(tem,"aspx","")
tem = Replace(tem,"cer","")
tem = Replace(tem,"cdx","")
tem = Replace(tem,"htr","")
if Int(InStr(tem,"."))<1 then
tem = "NotAllowFile"
else
tem = right(tem,len(tem)-InStr(tem,"."))
if trim(tem) = "" then tem = "NotAllowFile"
end if
formatFileName = tem
End Function
'验证文件类型.返回True/False
Private Function CheckFileExt(AllowStr,FileExtStr)
dim BoardUpload,i
BoardUpload = AllowStr
BoardUpload = Split(BoardUpload,",")
CheckFileExt = False
for i = 0 to UBound(BoardUpload)
if lcase(FileExtStr) = lcase(Trim(BoardUpload(i))) Then
CheckFileExt = True
Exit Function
end if
next
End Function
'判断文件Content-Type,是否为应用程序文件
Private Function NotFileType(FileType)
NotFileType = False
'response.write fileExt
if left(cstr(lcase(trim(FileType))),12)="application/" Then
if fileExt <> "rar" and fileExt <> "zip" then
NotFileType = True
response.write fileExt
end if
end if
End Function
'格式化当前时间
Function fomrmatTime()
fomrmatTime = Year(now)&Month(now)&Day(now)&Hour(now)&Minute(now)&Second(now)
End Function
%>
</td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -