上传、下载文件的asp页面怎么做?

aarongame 2008-04-16 02:59:28
通过后台上传文件到服务器中,然后再做一个页面,
能够显示所有上传的文件的名称,并且点这个文件名称就能下载文件。
怎么做?尽量给个完整的代码~~~~~~~~~
谢谢啦,有分的~
...全文
115 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xubaoshan 2008-04-17
  • 打赏
  • 举报
回复
网上的好多不能用,多下几个看看
icake 2008-04-16
  • 打赏
  • 举报
回复
网上多的是,下个研究一下,比如免费的BLOG系统,里面肯定有这东西。
scscms太阳光 2008-04-16
  • 打赏
  • 举报
回复
对了,把sfilename=JoinChar(sfilename)


'**************************************************
'函数名:JoinChar
'作 用:向地址中加入 ? 或 &
'参 数:strUrl ----网址
'返回值:加了 ? 或 & 的网址
'**************************************************
function JoinChar(strUrl)
if strUrl="" then
JoinChar=""
exit function
end if
if InStr(strUrl,"?") <len(strUrl) then
if InStr(strUrl,"?")>1 then
if InStr(strUrl,"&") <len(strUrl) then
JoinChar=strUrl & "&"
else
JoinChar=strUrl
end if
else
JoinChar=strUrl & "?"
end if
else
JoinChar=strUrl
end if
end function
代码删除吧,减肥!!
scscms太阳光 2008-04-16
  • 打赏
  • 举报
回复
<table width="100%" border="0" cellpadding="0" cellspacing="2" >
<tr>
<%

For Each theFile In theFolder.Files
c=c+1
if FileCount>=MaxPerPage then
exit for
elseif c>MaxPerPage*(CurrentPage-1) then
%>
<td>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="1" class='3d'>
<tr>
<td colspan="2" align="center" >
<%
strFileType=lcase(mid(theFile.Name,instrrev(theFile.Name,".")+1))
response.write "<a href='" & UploadDir & theFile.Name & "'>"
select case strFileType
case "jpg","gif","bmp","png"
response.write "<img src='" & UploadDir & theFile.Name & "' width='140' height='100' border='0' title='点击原图查看'></a>"
case else
response.write "<img src='images/SoftImages/filetype_other.gif' width='140' height='100' border='0' title='点击下载文件'></a>"
end select
%>
</td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF">文 件 名:</td>
<td bgcolor="#FFFFFF"><span style="cursor:hand;" title="点击复制图片地址" onclick="copyText('<%=UploadDir&theFile.Name%>');"><%=theFile.Name%></span></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF">文件大小:</td>
<td bgcolor="#FFFFFF"><%=round(theFile.size/1024) & " K"%></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF">文件类型:</td>
<td bgcolor="#FFFFFF"><%=theFile.type%></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF">修改时间:</td>
<td bgcolor="#FFFFFF"><%=theFile.DateLastModified%></td>
</tr>
</table>
</td>
<%
FileCount=FileCount+1
if FileCount mod 3=0 then response.write "</td><tr>"
if PageUnit=1 then
TotalSize_Page=TotalSize_Page+theFile.Size/1024
elseif PageUnit=2 then
TotalSize_Page=TotalSize_Page+theFile.Size/1024/1024
elseif PageUnit=3 then
TotalSize_Page=TotalSize_Page+theFile.Size/1024/1024/1024
end if
if TotalSize_Page>1024 then
TotalSize_Page=TotalSize_Page/1024
PageUnit=PageUnit+1
end if
if PageUnit=1 then
strPageUnit="KB"
elseif PageUnit=2 then
strPageUnit="MB"
elseif PageUnit=3 then
strPageUnit="GB"
end if
end if
Next
TotalSize_Page = Round(TotalSize_Page, 2)
%>
</tr>
</table>
</td></tr></table>
<%end sub%>
</body>
</html>
<%
sub showpage2(sfilename,totalnumber,maxperpage)
dim n, i,strTemp
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
strTemp= "<table align='center'><form name='showpages' method='Post' action='?'><tr><td>"
strTemp=strTemp & "共 <b>" & totalnumber & "</b> 个文件,占用 <b>" & TotalSize & "</b> " & strTotalUnit & "   "
sfilename=JoinChar(sfilename)
if CurrentPage<2 then
strTemp=strTemp & "首页 上一页 "
else
strTemp=strTemp & "<a href='?page=1'>首页</a> "
strTemp=strTemp & "<a href='?page=" & (CurrentPage-1) & "'>上一页</a> "
end if

if n-currentpage<1 then
strTemp=strTemp & "下一页 尾页"
else
strTemp=strTemp & "<a href='?page=" & (CurrentPage+1) & "'>下一页</a> "
strTemp=strTemp & "<a href='?page=" & n & "'>尾页</a>"
end if
strTemp=strTemp & " 页次:<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
strTemp=strTemp & " <b>" & maxperpage & "</b>" & "个文件/页"
strTemp=strTemp & " 转到:<select name='page' size='1' onchange='javascript:submit()'>"
for i = 1 to n
strTemp=strTemp & "<option value='" & i & "'"
if cint(CurrentPage)=cint(i) then strTemp=strTemp & " selected "
strTemp=strTemp & ">第" & i & "页</option>"
next
strTemp=strTemp & "</select>"
strTemp=strTemp & "</td></tr></form></table>"
response.write strTemp
end sub
'**************************************************
'函数名:JoinChar
'作 用:向地址中加入 ? 或 &
'参 数:strUrl ----网址
'返回值:加了 ? 或 & 的网址
'**************************************************
function JoinChar(strUrl)
if strUrl="" then
JoinChar=""
exit function
end if
if InStr(strUrl,"?")<len(strUrl) then
if InStr(strUrl,"?")>1 then
if InStr(strUrl,"&")<len(strUrl) then
JoinChar=strUrl & "&"
else
JoinChar=strUrl
end if
else
JoinChar=strUrl & "?"
end if
else
JoinChar=strUrl
end if
end function

'**************************************************
'函数名:IsObjInstalled
'作 用:检查组件是否已经安装
'参 数:strClassString ----组件名
'返回值:True ----已经安装
' False ----没有安装
'**************************************************
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function

%>
scscms太阳光 2008-04-16
  • 打赏
  • 举报
回复
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
response.buffer=true
Const MaxPerPage=18
dim strFileName
dim Action
dim totalPut,CurrentPage,TotalPages
dim UploadDir,TruePath,fso,theFolder,theFile,thisfile,FileCount,TotalSize,TotalSize_Page
dim TotalUnit,strTotalUnit,PageUnit,strPageUnit
dim strFileType
dim sql,rs,strFiles,i
if request("page")<>"" then
currentPage=cint(request("page"))
else
currentPage=1
end if

set rs=server.CreateObject("adodb.recordset")

UploadDir="flashbook/" '保存文件的文件夹,请修改
if right(UploadDir,1)<>"/" then
UploadDir=UploadDir & "/"
end if
TruePath=Server.MapPath(UploadDir)
%>

<head>
<meta name="robots" content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传文件管理</title>
<style>
body {
margin: 0px; font-size:12px;
background-color: #ffffff;
SCROLLBAR-FACE-COLOR:#F9F9F9;
SCROLLBAR-HIGHLIGHT-COLOR:#6E6E6E;
SCROLLBAR-SHADOW-COLOR:#6E6E6E;
SCROLLBAR-3DLIGHT-COLOR:red;
SCROLLBAR-ARROW-COLOR:red;
SCROLLBAR-TRACK-COLOR:#F5FFF0;
SCROLLBAR-DARKSHADOW-COLOR:#FAFAFA;
}
td{line-height: 120%;font-size:12px;}
.3d {border: #ff0000 1px solid;}
#help{width:97%;background:#ffffff;margin:auto;}
.p1{border:#eee 1px solid;}
.p2{border:#ddd 1px solid;}
.p3{border:#999 1px solid;padding:4px;}
</style>
</head>
<body>
<%
if not IsObjInstalled("Scripting.FileSystemObject") Then
Response.Write "<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
else
set fso=CreateObject("Scripting.FileSystemObject")
call main()
end if

sub main()
if fso.FolderExists(TruePath)=False then
response.write "找不到文件夹!可能是配置有误!"
exit sub
end if
FileCount=0
TotalSize=0
Set theFolder=fso.GetFolder(TruePath)
TotalUnit=1
For Each theFile In theFolder.Files
FileCount=FileCount+1
if TotalUnit=1 then
TotalSize=TotalSize+theFile.Size/1024
elseif TotalUnit=2 then
TotalSize=TotalSize+theFile.Size/1024/1024
elseif TotalUnit=3 then
TotalSize=TotalSize+theFile.Size/1024/1024/1024
end if
if TotalSize>1024 then
TotalSize=TotalSize/1024
TotalUnit=TotalUnit+1
end if
if TotalUnit=1 then
strTotalUnit="KB"
elseif TotalUnit=2 then
strTotalUnit="MB"
elseif TotalUnit=3 then
strTotalUnit="GB"
end if
next
TotalSize = Round(TotalSize, 2)
totalPut=FileCount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showContent
showpage2 strFileName,totalput,MaxPerPage
response.write "<br><div align='center'><b>当前文件夹:"&session("path")&"</b> 本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotalSize_Page & "</b> " & strPageUnit & "</div>"
else
if (currentPage-1)*MaxPerPage<totalPut then
showContent
showpage2 strFileName,totalput,MaxPerPage
response.write "<br><div align='center'><b>当前文件夹:"&session("path")&"</b> 本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotalSize_Page & "</b> " & strPageUnit & "</div>"
else
currentPage=1
showContent
showpage2 strFileName,totalput,MaxPerPage
response.write "<br><div align='center'><b>当前文件夹:"&session("path")&"</b> 本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotalSize_Page & "</b> " & strPageUnit & "</div>"
end if
end if
end sub
sub showContent()
dim c
FileCount=0
TotalSize_Page=0
PageUnit=1
%><center>
<div id="help"><div class="p1"><div class="p2"><div class="p3">
<table border="0" width="100%" cellpadding="0" cellspacing="0" align=center>
<tr>
<td>
myvicy 2008-04-16
  • 打赏
  • 举报
回复
上传的时候把保存的文件名和路径放到数据库里,然后显示的时候用数据的数据显示下载.
aarongame 2008-04-16
  • 打赏
  • 举报
回复
下载的页面怎么做??????????
要动态的
michel2l8 2008-04-16
  • 打赏
  • 举报
回复
我也想知道,能给个完整能用的吗?
lsf5921 2008-04-16
  • 打赏
  • 举报
回复
uploadfile
<a href="xxx.rar">xxx</a>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧