
<a href="?action=file&filename=aaaa.doc">生成aaaa.doc文檔</a>
該方法有一個(gè)不好的地方,就是所有的生成文件全是先保存在服務(wù)器上,然后再下載到本地。
<%
actions = trim(request("action"))
filenames=trim(request("filename")) '得到生成的文件名,待會(huì)用于生成與下載
if actions = "file" then
dim gongame '其實(shí)這個(gè)本來(lái)是想用模板,后來(lái)因?yàn)閿?shù)據(jù)真的太多,也懶得弄了。下面的只是一個(gè)示例
gongame = "<table cellpadding='0' cellspacing='1' class='utable' height='16'><tr><td class='utabletd8' height='16'><strong>系統(tǒng)</strong> - 個(gè)人簡(jiǎn)歷</td></tr></table><table cellpadding='0' cellspacing='1' class='utable'><tr><td class='utabletd7'>信息來(lái)源:自由注冊(cè) 注冊(cè)日期:"& time() &"</td></tr></table>"
Dim strTemplate
Dim FileObject '聲明一個(gè)FileSystemObject對(duì)象實(shí)例
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
Dim TextFile '聲明一個(gè)TextStream對(duì)象實(shí)例
Set TextFile= FileObject.CreateTextFile(Server.MapPath("word/"&filenames)) '把生成的文件存放在 word 目錄下。
TextFile.Write gongame
Set TextFile=Nothing
'以下代碼是用來(lái)下載剛才生成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
%>
呢 稱(chēng): | |
表 情: | |
內(nèi) 容: |
評(píng)論內(nèi)容:不能超過(guò) 1000 字,需審核,請(qǐng)自覺(jué)遵守互聯(lián)網(wǎng)相關(guān)政策法規(guī)。 |
驗(yàn)證碼: | |
您發(fā)布的評(píng)論即表示同意遵守以下條款:
一、不得利用本站危害國(guó)家安全、泄露國(guó)家秘密,不得侵犯國(guó)家、社會(huì)、集體和公民的合法權(quán)益;
二、不得發(fā)布國(guó)家法律、法規(guī)明令禁止的內(nèi)容;互相尊重,對(duì)自己在本站的言論和行為負(fù)責(zé);
三、本站對(duì)您所發(fā)布內(nèi)容擁有處置權(quán)。