|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
asp对于服务器的要求较高,一般的服务器如果访问量一大就垮了,不得不重启。下载能够用流下载(耗内存,罕用)或间接转到该文件.
<%
ConstUSE_STREAM=00.不必流(Adodb.Stream)下载1.用流下载
ConstALLOW_FILE_EXT="rar,zip,chm,doc,xls,swf,mp3,gif,jpg,jpeg,png,bmp"同意下载的文件的扩大名,避免源代码被下载
DimsDownFilePath下载文件路径
sDownFilePath=Trim(Request("FilePath"))
大概依据传过去的文件ID从数据库中猎取文件路径
假如sDownFilePath为相对路径,必定要将sDownFilePath转换为绝对本文件的绝对路径
sDownFilePath="focus.swf"
CallDownloadFile(sDownFilePath)
FunctionDownloadFile(s_DownFilePath)
判别有没传送文件名
IfIsNull(s_DownFilePath)=TrueOrTrim(s_DownFilePath)=""Then
OutputErr"毛病:先断定要下载的文件,下载失利"
EndIf
判别扩大名是不是正当
Dims_FileExt
s_FileExt=Mid(s_DownFilePath,InstrRev(s_DownFilePath,".")+1)
IfInStr(","&ALLOW_FILE_EXT&",",","&s_FileExt&",")<=0Then
OutputErr"毛病:文件范例("&s_FileExt&")不同意被下载,下载失利"
EndIf
s_DownFilePath=Replace(s_DownFilePath,"","/")
为了平安,某些目次克制下载文件,在这里处置
检测服务器是不是撑持fso
Dimo_Fso
OnErrorResumeNext
Seto_Fso=Server.CreateObject("Scripting.FileSystemObject")
IfErr.Number0Then
Err.Clear
OutputErr"毛病:服务器不撑持fso组件,下载失利"
EndIf
获得文件名,文件巨细
Dims_FileMapPath
Dimo_File,s_FileName,n_FileLength
s_FileMapPath=Server.MapPath(s_DownFilePath)
If(o_Fso.FileExists(s_FileMapPath))=TrueThen
Seto_File=o_Fso.GetFile(s_FileMapPath)
s_FileName=o_File.Name
n_FileLength=o_File.Size
o_File.Close
Else
OutputErr"毛病:文件不存在,下载失利"
EndIf
Seto_Fso=Nothing
判别是不是下载的文件巨细凌驾限定
假如不是用流下载,间接转到该文件
IfUSE_STREAM=0Then
Response.RedirectsDownFilePath
Response.end
EndIf
检测服务器是不是撑持Adodb.Stream
OnErrorResumeNext
Seto_Stream=Server.CreateObject("Adodb.Stream")
IfErr.Number0Then
Err.Clear
OutputErr"毛病:服务器不撑持Adodb.Stream组件,下载失利"
EndIf
o_Stream.Tyep=1
o_Stream.Open
o_Stream.LoadFromFiles_FileMapPath
Response.Buffer=True
Response.Clear
Response.AddHeader"Content-Disposition","attachment;filename="&s_FileName
Response.AddHeader"Content-Length",n_FileLength
Response.CharSet="UTF-8"
Response.ContentType="application/octet-stream"
Response.BinaryWriteo_Stream.Read
Response.Flush
o_Stream.Close
Seto_Stream=Nothing
EndFunction
SubOutputErr(s_ErrMsg)
Response.Write"<fontcolor=red>"&s_ErrMsg&"</font>"
Response.End
EndSub
%>
http://www.ckuyun.com/jiny-z/archive/2006/08/29/489102.html
结论:和PHP一样,ASP简单而易于维护,很适合小型网站应用,通过DCOM和MTS技术,ASP甚至还可以完成小规模的企业应用,但ASP的致命缺点就是不支持跨平台的系统,在大型项目开发和维护上非常困难。 |
|