📄 avatars.asp
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
response.Buffer = true
Server.ScriptTimeOut=5000
%>
<!--#Include file = "BBSConfig.asp"-->
<!--#include file="Session.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户头像管理</title>
<link href="Style.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="0" topmargin="0">
<%
Function delfile(delname)
On Error Resume Next
dim dname
dname = delname
Set MyFileObject = Server.CreateObject("Scripting.FileSystemObject")
MyFileObject.DeleteFile Server.MapPath(dname)
Set MyFileObject = Nothing
End Function
action = Trim(Request.QueryString("action"))
SELECT Case action
Case "add"
Call add()
Case "SaveNew"
Call SaveNew()
Case "Del"
Call Del()
Case else
Call list()
End SELECT
'======================
Sub add()
UpimgFolder = "../images/avatars/"
%>
<br>
<br>
<br>
<table width="319" border="0" align="center" cellpadding="3" cellspacing="1">
<form name="form" method="post" action="?action=SaveNew" enctype="multipart/form-data">
<tr>
<td><strong>上传头像</strong></td>
</tr>
<tr>
<td>
<input name="filepath" type="hidden" id="filepath" value="<%=UpimgFolder%>">
<input type="hidden" name="fname"> <input name="file1" type="file" class="input2" size="20">
<input name="Submit" type="submit" class="input2" value="上传">
</td>
</tr>
</form>
</table>
<%
End Sub
'====================================
Sub SaveNew()
%>
<!--#include file="upload.inc"-->
<%
dim upload,file,formName,formPath,iCount,times,fileExt,filename
times = now()
times = replace(times,"-","")
times = replace(times," ","")
times = replace(times,":","")
times = replace(times,"PM","")
times = replace(times,"AM","")
times = replace(times,"上午","")
times = replace(times,"下午","")
set upload=new upload_5xsoft ''建立上传对象
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
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>]"
response.End
set upload = Nothing
end if
fileExt=lcase(file.FileName)
'判断文件类型
if Right(fileEXT,3)="asp" Or Right(fileEXT,3)="asa" Or Right(fileEXT,4)="aspx" then
response.write"文件类别错误,[<a href=""javascript:history.back();"">返回</a>]"
set upload=nothing
response.end
end if
file.SaveAs Server.mappath(formPath×&"_"&file.FileName) ''保存文件
iCount=iCount+1
FileURL=formPath×&"_"&file.FileName
pic_name = times&"_"&file.FileName
set file=nothing
next
'将文件路径写入数据库
Conn.ExeCute("insert into JBB_avatars(pic_Name) values('"& pic_name &"')")
set upload=nothing ''删除此对象
Htmend " 图片上传完毕! <a href="""&FileURL&""" target=""_blank"">查看图片</a>"
End Sub
sub HtmEnd(Msg)
set upload=nothing
response.write Msg&" [<a href=""javascript:history.back();"">再次上传</a>]"
response.end
end sub
'====================================
Sub list()
set rs = server.CreateObject("adodb.recordset")
rs.open "select pic_Name From JBB_avatars order By ID asc",conn,1,1
if Not(rs.Eof and rs.Bof) then
page = trim(request.QueryString("page"))
if Not(IsNumeric(page)) or page = "0" then page = 1
rs.pageSize = 25
pageCount = rs.pageCount
if len(page) > 4 then page = pageCount
if Cint(page) > Cint(pageCount) then page = pageCount
rs.absolutepage = page
%>
<br>
<table width="560" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#EFEFE7"><strong>编辑头像</strong></td>
</tr>
</table>
<table width="560" border="1" align="center" cellpadding="3" cellspacing="3" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
<%
For i = 1 to 5
if rs.Eof then Exit for
%>
<tr>
<%
For j = 1 to 5
if rs.Eof then Exit for
%>
<td bgcolor="#FFFFFF"> <div align="center"><img src="../images/avatars/<%=rtrim(rs(0))%>"><br>
[<a href="?action=Del&pic_Name=<%=rtrim(rs(0))%>">删除</a>]
</div></td>
<%
rs.MoveNext
Next'j
%>
</tr>
<%
Next'i
%>
</table>
<table width="560" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td width="237"> <%
if pagecount < 1 then pagecount = 1
response.Write " 页次:"& PAGECOUNT &"/" & page &"页 每页"& rs.pageSize &" 头像数"&rs.recordCount&" "
%> </td>
<td width="307" height="30">分页:
<%
beginpage = 1
endpage = CInt(pagecount)
page = CInt(page)
if pagecount >= 9 then
if page >= 5 then
beginpage = page - 4
if page <= (pagecount - 4) then
endpage = page + 4
else
endpage = pagecount
beginpage = pagecount - 4
end if
else
beginpage = 1
endpage = 9
end if
end if
if beginpage>1 then response.write " <a title=""第一页"" href=""avatars.asp""><font face=webdings>9</font></a>"
for j = beginpage to endpage
if j = page then
response.write" <b>" & j & "</b> "
else
response.write"<a href=""avatars.asp?page=" & j &"""> " & j & " </a>"
end if
next
if endpage < pagecount then response.write " <a title=""最末页"" href=""avatars.asp?page="& pagecount &"""><font face=webdings>:</font></a>"
%> </td>
<form name="form1" method="post" action="">
</form>
</tr>
</table>
<br>
<%
else
response.Write("<br><br> 暂时没有任何头像!~")
End if
rs.close
set rs = nothing
End Sub
'==============================
Sub Del()
pic_Name = trim(request.QueryString("pic_name"))
if pic_name <> "" then
delFile("../images/avatars/"&pic_name)
Conn.ExeCute("Delete From JBB_avatars where pic_Name='" & pic_Name & "'")
response.Write("<br><br> 删除完毕!~")
End if
End Sub
%>
</body>
</html>
<%
set conn=nothing
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -