我想创建一个页面,可以显示消息“您的下载即将开始”,然后几秒钟后打开“另存为”对话框,允许访问者下载文件。这在经典的ASP VB脚本中可能吗?我知道如何制作页面流文件,但它不显示页面的HTML。我提供的文件是20Mb,因此脚本需要处理大文件大小。经典的ASP下载PDF页面加载
我现在有一个元重定向到位:
<meta http-equiv="refresh" content="2; url=/downloads/brochures/ACET_Products_and_Services_Directory_2013-14.pdf" />
但是,这不是什么好的。
我已经安装在服务器上asppdf,这给了一展身手:
<%
Set Pdf = Server.CreateObject("Persits.Pdf")
Set Doc = Pdf.OpenDocument("d:/websites/common/downloads/brochures/ACET_Products_and_Services_Directory_2013-14.pdf")
Doc.SaveHttp "attachment;filename=ACET_Products_and_Services_Directory_2013-14.pdf"
%>
这得到各地的大文件,但你不能流在同一时间的文件,并显示HTML。
我发现有很多方法可以将文件流式传输到浏览器,但是我不能在页面显示后做到这一点。
这是另外一个我曾尝试:
<%
Response.Buffer = False
Server.ScriptTimeout = 30000
Response.ContentType = "application/x-unknown" ' arbitrary
fn = "ACET_Products_and_Services_Directory_2013-14.pdf"
FPath = "d:\websites\common\downloads\brochures\" & fn
Response.AddHeader "Content-Disposition", "attachment; filename=" & fn
Set adoStream = CreateObject("ADODB.Stream")
chunk = 2048
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(FPath)
iSz = adoStream.Size
Response.AddHeader "Content-Length", iSz
For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next
If iSz Mod chunk > 0 Then
If Response.IsClientConnected Then
Response.BinaryWrite adoStream.Read(iSz Mod chunk)
End If
End If
adoStream.Close
Set adoStream = Nothing
Response.End
%>
有了这个,我得到一个错误代码:从Chrome中ERR_INVALID_RESPONSE。
这是一个我已经试过,几乎工作:
<%
strFilePath = "d:/web sites/common/downloads/brochures/ACET_Products_and_Services_Directory_2013-14.pdf"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFilePath) Then
Set objFile = objFSO.GetFile(strFilePath)
intFileSize = objFile.Size
Set objFile = Nothing
strFileName = "ACET_Products_and_Services_Directory_2013-14.pdf"
Response.AddHeader "Content-Disposition","attachment; filename=" & strFileName
Response.ContentType = "application/x-msdownload"
Response.AddHeader "Content-Length", intFileSize
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1 'adTypeBinary
objStream.LoadFromFile strFilePath
Do While Not objStream.EOS And Response.IsClientConnected
Response.BinaryWrite objStream.Read(1024)
Response.Flush()
Loop
objStream.Close
Set objStream = Nothing
Else
Response.write "Error finding file."
End if
Set objFSO = Nothing
%>
然后我用<%的Response.Redirect(“download.asp”)%>我希望它从下载页面上,但只要我打开页面,我会得到文件,但没有页面。它的这一部分我正在努力。
SUCCESS!
<script>
window.location.replace('download.asp');
</script>
干杯,
史蒂夫
是的,这是可能的。 – Lankymart 2014-09-12 12:21:55
Lankymart说的是我们不会为你写代码。告诉我们你试过了什么,我们可以给你指出什么是错的。网上还有很多关于[如何延迟]的内容(http://classicasp.aspfaq.com/general/how-do-i-make-my-asp-page-pause-or-sleep.html)和[推送文件](https://blog.netnerds.net/2007/01/classic-asp-push-file-downloads-from-directory-outside-of-the-web-root/)。 – Paul 2014-09-12 13:36:58