1. 儲存至伺服器中
<%
Dim id_srl 'request.QueryString("id_srl")
id_srl=49
if Cint(id_srl) >0 then
Dim Conn,ConnStr,Rs,Sql,MyStream
ConnStr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=fdp_user;Initial Catalog=FDP;Data Source=10.120.120.153;Locale Identifier=1036;Connect Timeout=15;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;"
Set Conn = Server.CreateObject("Adodb.Connection")
Conn.Open ConnStr,"fdp_user","rlxhamster"
Sql = "select * from srl_contenu where id_srl="& id_srl
Set Rs = Server.CreateObject("Adodb.RecordSet")
Rs.Open Sql,Conn,1,3
Set objStream=Server.CreateObject("Adodb.Stream")
objStream.Type = 1
objStream.Open
objStream.Write Rs("Contenu").GetChunk(rs("Contenu").ActualSize-78)
objStream.SaveToFile server.MapPath("db")& "\" & Rs("Nom_fichier"),2
Set fso=Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(server.MapPath("db")& "\" & Rs("Nom_fichier"))=True Then
response.write "File "& Rs("Nom_fichier") & " saved success!!"
end if
objStream.Close
set objStream=Nothing
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
end if
%>
2.下載檔案樣本
<%
'設定檔案的大小及MIME類型
Function SetForDisplay(field, contentType)
contentType = LCase(trim(contentType))
nFieldSize = field.ActualSize
bytes = field.GetChunk(nFieldSize)
Session("Bytes") = bytes
Session("Type") = contentType
End Function
Function SetFileSize(field)
nFieldSize = field.ActualSize
SetFileSize = field.GetChunk(nFieldSize)
End Function
SetForDisplay rs("Contenu"),rs("Content_type")
Response.AddHeader "Content-Disposition", "attachment; filename=" & rs("Nom_fichier")
response.contentType = Session("Type")
response.BinaryWrite Session("Bytes")
Session("Type") = ""
Session("Bytes") = ""
%>