我处于用户点击下载按钮时调用流连接的情况。提交下载按钮时,将在ASP中调用一个函数,其中下载代码在文件BD_Test1.txt
上执行。此文本文件的内容只是TEST 1
。
文件正常下载,但打开时,所有HTML代码都在文本文件中。
<html>
<head>
<title>Bulk Download Zipper</title>
<!--#include file="BD_Download.asp"-->
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
<%
If (Request.Form("zipFile") <> "") Then
Call downloadFile()
End If
%>
</body>
</html>
<%
Function downloadFile()
Dim download_File, download_Remove, download_Autoremove
Set download_File = Server.CreateObject("ADODB.Stream")
download_File.Type = 1
download_File.Open
download_File.LoadFromFile("E:\inetpub\wwwroot\cdc\wnyaccc_erie_niagara_trd-2\youkergav\BulkDownload\resumes\BD_Test1.txt")
Response.AddHeader "Content-Transfer-Encoding", "binary"
Response.AddHeader "Content-Description", "File Transfer"
Response.AddHeader "Content-Disposition", "attachment; filename=Resumes.txt"
Response.CharSet = "UTF-8"
Response.ContentType = "text/plain"
Response.BinaryWrite download_File.Read
download_File.Close
Set download_File = Nothing
End Function
%>
<html>
<head>
<title>Bulk Download Zipper</title>
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
TEST 1
</body>
</html>
如您所见,正在插入文本文件的内容,其中调用了downloadFile()
函数。是否有可能以这种方式使用流连接?
答案 0 :(得分:2)
在页面已经开始提供给客户端后,您的downloadFile
功能被称为。 ASP只是简单地注入你的函数的结果。您需要在POST上覆盖整个输出。在GET上输出html,并在POST上输出文本文件:
<%
If (Request.Form("zipFile") <> "") Then
Call downloadFile()
Else%>
<html>
<head>
<title>Bulk Download Zipper</title>
<!--#include file="BD_Download.asp"-->
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
</body>
</html>
<%
End If
%>