default ASP
=========
<HTML>
<BODY>
<p><font size="6">P</font><b><font size="6">ls Download Your File</font></b></p>
<p>========================================================</p>
<%
dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("c:\upload\")
for each x in fo.files
'Print the name of all files in the test folder
'Response.write(x.Name & "<br />")
Response.write ( "<a href='load.asp?filename="& x.Name & " '>" & x.Name & "</a> <br>")
next
set fo=nothing
set fs=nothing
%>
</BODY>
</HTML>
=================================
‘读取某个路径的文件夹内的所有文件并创建链接
load.asp
===============
<%
'**************************************************************
'**使用方法: **
'**在点击下载处加连接<a href="load.asp?filename=文件名"></a> **
'**阳光白雪——2005年11月21日 **
'**E-mail:chenmanyi0818@126.com **
'**HomePage:http://www.toumh.com ; **
'**************************************************************
'**************************************************
'** 实现文件下载函数 **
'**************************************************
Function Filedownload(filename)
Dim strchar,fliesend,objectFile,objfile,objStream,path,pathtype
pathtype = "application/x-msdownload"
path = server.MapPath("download/"&filename)
Const loadfilesize=32768 '32KB,也可取其它值,单位:字节
'在给path赋值后,其最终值必定是该图片在服务器端存储器上的绝对路径,如 C:\Inetpub\wwwroot\pic\help.gif
'因为 server.MapPath 取得的只是站点根目录的路径,所以在后面还应加上文件所在的文件夹再加文件名
'例如:要下载的文件 setup.exe 在根目录的 download 文件夹下,则 path = server.MapPath("download/"&filename)
'***********************************
'测试用
'response.Write(path)
'response.Write(filename)
'response.End()
'***********************************
fliesend=0
TransferFile = True
Set objectFile = Server.CreateObject("Scripting.FileSystemObject")
Set objfile = objectFile.GetFile(Path)
Set objStream = objfile.OpenAsTextStream(1,-1)
Response.AddHeader "content-type", pathtype
response.AddHeader "Content-Disposition","p_w_upload;filename="&filename
Response.AddHeader "content-length", objfile.Size
Do While Not objStream.AtEndOfStream
strchar = objStream.Read(1)
Response.BinaryWrite(strchar)
fliesend = fliesend + 1
If (fliesend MOD loadfilesize) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
end if
objStream.Close
Set objStream = Nothing
Set objectFile = Nothing
End Function
'****************************************************
'** 文件下载函数结束 **
'****************************************************
Dim fileneme,downloadfile
filename = request("filename") '此处的 filename 仅为下载文件的名称(包括扩展名)
downloadfile = Filedownload(filename) '调用文件下载函数
Response.End
%>
转载于:https://blog.51cto.com/ericfu/1902039