
<a href="?action=file&filename=aaaa.doc">生成aaaa.doc文檔</a>
該方法有一個不好的地方,就是所有的生成文件全是先保存在服務器上,然后再下載到本地。
<%
actions = trim(request("action"))
filenames=trim(request("filename")) '得到生成的文件名,待會用于生成與下載
if actions = "file" then
dim gongame '其實這個本來是想用模板,后來因為數據真的太多,也懶得弄了。下面的只是一個示例
gongame = "<table cellpadding='0' cellspacing='1' class='utable' height='16'><tr><td class='utabletd8' height='16'><strong>系統</strong> - 個人簡歷</td></tr></table><table cellpadding='0' cellspacing='1' class='utable'><tr><td class='utabletd7'>信息來源:自由注冊 注冊日期:"& time() &"</td></tr></table>"
Dim strTemplate
Dim FileObject '聲明一個FileSystemObject對象實例
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
Dim TextFile '聲明一個TextStream對象實例
Set TextFile= FileObject.CreateTextFile(Server.MapPath("word/"&filenames)) '把生成的文件存放在 word 目錄下。
TextFile.Write gongame
Set TextFile=Nothing
'以下代碼是用來下載剛才生成aaaa.doc 文件
Const ForReading=1
Const TristateTrue=-1
Const FILE_TRANSFER_SIZE=16384
Response.Buffer = True
Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(Path)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type", mimeType
response.AddHeader "Content-Disposition","attachment;filename=" & filename
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function
Dim path, mimeType, sucess,downfilename
downfilename="word/"&request("filename")
path = Server.MapPath(downfilename)
mimeType="text/plain"
sucess = TransferFile(path, mimeType,downfilename)
Response.End
end if
%>
您發布的評論即表示同意遵守以下條款:
一、不得利用本站危害國家安全、泄露國家秘密,不得侵犯國家、社會、集體和公民的合法權益;
二、不得發布國家法律、法規明令禁止的內容;互相尊重,對自己在本站的言論和行為負責;
三、本站對您所發布內容擁有處置權。