|
ASP实现文件直接下载
主程序代码如下: -------------------------------------------------------------------------------- 定义所有需要使用的变量 Dim strFilename,S,Fso,F,intFilelength strFilename = Server.MapPath(Trim(Request("File"))) Response.Buffer = True Response.Clear Set S = Server.CreateObject("ADODB.Stream") S.Open S.Type = 1 On Error Resume Next Set Fso = Server.CreateObject("Scripting.FileSystemObject") If Not Fso.FileExists(strFilename) Then Response.Write(" Error:"&strFilename&"你要下载的文件不存在!") Response.End End If Set F = Fso.GetFile(strFilename) intFilelength = F.Size 获取文件大小 S.LoadFromFile(strFilename) If Err Then Response.Write(" Error:Unknown Error!") Response.End End If Response.AddHeader "Content-Disposition","attachment;filename="&F.name Response.AddHeader "Content-Length",intFilelength Response.CharSet = "GB2312" Response.ContentType = "application/octet-stream" Response.BinaryWrite S.Read Response.Flush S.Close Set S = Nothing |
|
Time.2009-8-3 来源.http://www.gcity.com.cn 编辑.上海红提城信息科技有限公司
|
© 2002-2008 www.Gcity.com.cn 沪ICP备06055129号咨询热线:4008207959 021-33606181(红提城信息科技)
|