不用WinRar只有asp将网络空间上的文件打包下载(3)
Public Sub RemoveFile(sFilename)
objFiles.Remove sFilename
End Sub
Public Sub AddMemoryFile(sFilename,sContents)
objMemoryFiles.Add sFilename,sContents
End Sub
Public Sub RemoveMemoryFile(sFilename)
objMemoryFiles.Remove sFilename
End Sub
' Send the tarball to the browser
Public Sub WriteTar()
Dim objStream, objInStream, lTemp, aFiles
Set objStream = Server.CreateObject("ADODB.Stream") ' The main stream
Set objInStream = Server.CreateObject("ADODB.Stream") ' The input stream for data
objStream.Type = 2
objStream.Charset = "x-ansi" ' Good old extended ASCII
objStream.Open
objInStream.Type = 2
objInStream.Charset = "x-ansi"
' Go through all files stored on disk first
aFiles = objFiles.Items
For lTemp = 0 to UBound(aFiles)
objInStream.Open
objInStream.LoadFromFile aFiles(lTemp)
objInStream.Position = 0
'ExportFile aFiles(lTemp),objStream,objInStream
TmpFileName =replace(aFiles(lTemp),Server.Mappath(Path)&"\","")
ExportFile TmpFileName,objStream,objInStream
objInStream.Close
Next
' Now add stuff from memory
aFiles = objMemoryFiles.Keys
For lTemp = 0 to UBound(aFiles)
objInStream.Open
objInStream.WriteText objMemoryFiles.Item(aFiles(lTemp))
objInStream.Position = 0
ExportFile aFiles(lTemp),objStream,objInStream
objInStream.Close
Next
objStream.WriteText String(BlockSize,Chr(0))
' Rewind the stream
' Remember to change the type back to binary, otherwise the write will truncate
' past the first zero byte character.
objStream.Position = 0
objStream.Type = 1
' Set all the browser stuff
Response.AddHeader "Content-Disposition","filename=" & TarFilename
Response.ContentType = "application/x-tar"
内容版权声明:除非注明,否则皆为本站原创文章。