Make up to download with Adodb.Stream

xiaoxiao2021-03-06  39

Function loadFile (Byval file)

DIM Objstream

ON Error ResMe next

Set objstream = Server.createObject ("adodb.stream")

IF err.number = -2147221005 THEN

Response.write "

"

Err.clear

Response.end

END IF

With objstream

.Type = 2

.Mode = 3

.Open

.Loadfromfile server.mappath (file)

IF Err.Number <> 0 THEN

Response.write "

File " & file & " cannot be opened, please check if there is existence! "

Err.clear

Response.end

END IF

.Charset = "GB2312"

.Position = 2

LoadFile = .readtext

.Close

End with

Set objstream = Nothing

END FUNCTION

'Store content to file

Sub Savetofile (Byval File)

DIM Objstream

ON Error ResMe next

Set objstream = Server.createObject ("adodb.stream")

IF err.number = -2147221005 THEN

Response.write "

"

Err.clear

Response.end

END IF

With objstream

.Type = 2

.Open

.Charset = "GB2312"

.Position = objstream.size

.Writetext = STRBODY

.Savetofile server.mappath (file), 2

.Close

End with

Set objstream = Nothing

End Sub

Download STREAM Technology

Function DL (f, n)

ON Error ResMe next

Set s = createObject ("AdoDb.Stream")

S.Mode = 3

S.TYPE = 1

S.Open

S.LoadFromFile (f)

IF err.number> 0 THEN

Response.status = "404"

Else

Response.contentType = "Application / OcTet-stream"

Response.addheader "Content-Disposition:", "Attachment; FileName =" & n

Range = MID (Request.ServerVariables ("http_range"), 7) if Range = "" "

Response.binaryWrite (S.READ)

Else

S.Position = clng (split (range, "-") (0))

Response.binaryWrite (S.READ)

END IF

END IF

Response.end

END FUNCTION

Sample example of function:

Call DL (Server.mAppath ("../ Download / 07.zip"), "07.zip")

转载请注明原文地址:https://www.9cbs.com/read-75877.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.041, SQL: 9