天天看點

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

<%

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

filepath=request.querystring("filepath")

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

filenames=Split(filepath,"/")

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

filename=filenames(1)

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Const ForReading=1

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Const TristateTrue=-1 'Unicode

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Const FILE_TRANSFER_SIZE=16384 '16k

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

'Use the following line for IIS4/PWS - this is the default for IIS5

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Response.Buffer = True

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Function TransferFile(path, mimeType, filename)

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Dim objFileSystem, objFile, objStream

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Dim char

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Dim sent

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

send=0

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

TransferFile = True

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Set objFile = objFileSystem.GetFile(Path)

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Response.AddHeader "content-type", mineType

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Response.ContentType = "application/octet-stream"

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

response.AddHeader "Content-Disposition","attachment;filename="&filename 

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Response.AddHeader "content-length", objFile.Size

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Do While Not objStream.AtEndOfStream

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

char = objStream.Read(1)

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Response.BinaryWrite(char)

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

sent = sent + 1

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

If (sent MOD FILE_TRANSFER_SIZE) = 0 Then

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Response.Flush

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

If Not Response.IsClientConnected Then

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

TransferFile = False

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Exit Do

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

End If

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Loop

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

If Not Response.IsClientConnected Then TransferFile = False

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

objStream.Close

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Set objStream = Nothing

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Set objFileSystem = Nothing

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

End Function

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Dim path, mimeType, sucess

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

path = Server.MapPath(filepath)

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

mimeType = "application/octet-stream" 

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

sucess = TransferFile(path, mimeType,filename)

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式
asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

Response.End

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

%>

asp的一個下載下傳功能頁面,就是把檔案直接傳給用戶端的方式

繼續閱讀