自己写下载的超难问题!

gzamao 2006-06-21 03:44:46
我的abc.asp如下,目的是自己写下载过程,不直接连到文件上去
<%
dim abc
abc=67
Response.AddHeader "content-type", "text/plain"
response.AddHeader "Content-Disposition","attachment;filename="
Response.AddHeader "content-length","1"
response.binarywrite abc
response.flush
%>

调用页面temp.asp如下:
<html>
<body>
<a href="abc.asp">hello</a>
</body>
</html>

但从temp中一点hello,就出现这种错误:
Internet Explorer无法打开该Internet站点。请求的站点不可用,或找不到……
到底哪出了问题?
...全文
271 17 打赏 收藏 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzamao 2006-07-06
  • 打赏
  • 举报
回复
楼上的朋友,把你的代码给个最简版,行吗?谢了.
gzamao 2006-07-05
  • 打赏
  • 举报
回复
谁要是能把这段代码修改好,下栽成功,重重有赏!!!
gzamao 2006-07-05
  • 打赏
  • 举报
回复
楼上的,ASP里可以dim abc as byte吗?
超难!!
yc1042 2006-07-05
  • 打赏
  • 举报
回复
我解决了
各位给出的代码都应该没问题,我是在网页的开始加上了<%Response.CacheControl = "No-Cache"%>这么一句,禁止网页缓存。
其实文件是被正常下载到了客户端但是由于不能缓存到临时文件夹导致 windows找不到需要打开的文件而报错。去掉禁止网页缓存后就正常了
不知道楼主与到的情况是不是和我一样
yc1042 2006-07-05
  • 打赏
  • 举报
回复
我遇到同样的问题(浏览器使用IE时)
一笑拔剑 2006-06-29
  • 打赏
  • 举报
回复
dim那里定义了
呵呵
你定义为 dim abc as byte
gicjoe 2006-06-29
  • 打赏
  • 举报
回复
這兩个文件放在同一目錄下
postcode 2006-06-29
  • 打赏
  • 举报
回复
路过,留个标签
patchclass 2006-06-28
  • 打赏
  • 举报
回复
response.binarywrite abc
你的abc根本不是二进制数据!!
net205 2006-06-28
  • 打赏
  • 举报
回复
用cestar2005(往事随风)的试试.
gzamao 2006-06-28
  • 打赏
  • 举报
回复
楼上的,我的问题出在哪还没能找出来,还是不能下载.我只写一个字节的文件,难道不行吗?
gzamao 2006-06-28
  • 打赏
  • 举报
回复
楼上的朋友,那abc怎么定义才是算是二进制?
八哥 2006-06-21
  • 打赏
  • 举报
回复
Response.AddHeader "content-length","1"
是不是长度与实际长度不配
cestar2005 2006-06-21
  • 打赏
  • 举报
回复
上面那条写错了,是回答别人问题的
cestar2005 2006-06-21
  • 打赏
  • 举报
回复
Request.ServerVariables("PATH_INFO")
Request.ServerVariables("URL")
Request.ServerVariables("script_name")
都可以得到当前页的文件名,根据你的情况自已处理下吧
详细说明
http://tians.lnfs.net/article.asp?id=57
cestar2005 2006-06-21
  • 打赏
  • 举报
回复
我写的下载代码,你看下对你有没有用
<%
Response.Buffer = true
Response.Clear
Dim url
Dim fl,flsize
dim Dname
Dim objStream,ContentType,flName,isre,url1
'*********************************************调用时传入的下载文件名

FilePath=Server.MapPath("DownLoad\"&FilePath) 'DownLoad为下载文件存放目录,FilePath这里为文件名,因为我省略掉了从数据库读取文件名的CODE

'******************************下载文件存放的服务端目录

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile FilePath
IF Err.Number>0 Then
Response.Status="404"
Response.End()
End IF

Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set fl=fso.getfile(FilePath)
flsize=fl.size
flName=fl.name
Set fl=Nothing
Set fso=Nothing

Select Case lcase(Right(flName, 4))
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".bmp"
ContentType = "image/bmp"
Case ".ppt"
ContentType = "application/vnd.ms-powerpoint"
Case ".mdb"
ContentType = "application/x-msaccess"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".txt"
ContentType = "text/plain"
Case Else
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename=" & flName
Response.AddHeader "Content-Length", flsize
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
response.Clear()
objStream.Close
Set objStream = Nothing
%>
  • 打赏
  • 举报
回复
看不懂

28,402

社区成员

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

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