Vbscript 经典ASP下载PDF页面加载
我想创建一个页面,可以显示一条消息“您的下载即将开始”,然后在几秒钟后打开一个“另存为”对话框,允许访问者下载文件。这在经典的ASP VB脚本中可能吗?我知道如何使页面流成为文件,但它不显示页面的html。我提供的文件是20Mb,因此脚本需要处理大文件 我目前有一个元重定向:Vbscript 经典ASP下载PDF页面加载,vbscript,asp-classic,Vbscript,Asp Classic,我想创建一个页面,可以显示一条消息“您的下载即将开始”,然后在几秒钟后打开一个“另存为”对话框,允许访问者下载文件。这在经典的ASP VB脚本中可能吗?我知道如何使页面流成为文件,但它不显示页面的html。我提供的文件是20Mb,因此脚本需要处理大文件 我目前有一个元重定向: <meta http-equiv="refresh" content="2; url=/downloads/brochures/ACET_Products_and_Services_Directory_2013-14
<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
%>
然后我在我想下载的页面上使用了,但是我一点击页面就得到了文件,但是没有页面。这是我正在努力解决的问题
成功
<script>
window.location.replace('download.asp');
</script>
window.location.replace('download.asp');
干杯
Steve经过更多的尝试和错误,我发现创建一个名为download.asp的文件并将此代码放入其中是可行的:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
strFilePath = "d:/websites/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/pdf"
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
%>
通过更多的尝试和错误,我发现创建了一个名为download.asp的文件,并将此代码放入了工作:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
strFilePath = "d:/websites/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/pdf"
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
%>
Lankymart所说的是我们不会为您编写代码。向我们展示您的尝试,我们可以为您指出问题所在。网络上也有很多东西,Lankymart说的是我们不会为你写代码。向我们展示您的尝试,我们可以为您指出问题所在。网上也有很多东西。
<script>
window.location.replace('download.asp');
</script>