<%
sql2 = "select * from sentwork,exercise where sw_exid="&request("exid")&" and sw_exid=ex_id "
Set objRec2 = Server.CreateObject("ADODB.Recordset")
objRec2.Open sql2, Conn
Dim objFSO, objStream,i
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objStream = objFSO.CreateTextFile(Server.MapPath("ex_score/ex"&request("exid")&"_score.txt"),true)
do while not objRec2.eof
objStream.WriteLine objRec2("sw_std")&" = "&objRec2("sw_score")
objRec2.movenext
loop
objRec2.close
objStream.Close
Set objStream = Nothing
Set objFSO = Nothing
response.redirect "ex_score/ex"&request("exid")&"_score.txt" 'ตรงนี้ผมกะจะให้มันลิ้งค์ไปที่ไฟล์นั้นเลย
%>
ผมแปะไปแบบนี้ผิดตรงไหนหรือเอาโค้ดมาไม่หมดครับ
Code (ASP)
<%
sql2 = "select * from sentwork,exercise where sw_exid="&request("exid")&" and sw_exid=ex_id "
Set objRec2 = Server.CreateObject("ADODB.Recordset")
objRec2.Open sql2, Conn
Dim objFSO, objStream,i
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objStream = objFSO.CreateTextFile(Server.MapPath("ex_score/ex"&request("exid")&"_score.txt"),true)
objStream.WriteLine "ª×èÍ㺧ҹ "&objRec2("ex_name")
do while not objRec2.eof
objStream.WriteLine objRec2("sw_std")&" = "&objRec2("sw_score")
objRec2.movenext
loop
objRec2.close
objStream.Close
Set objStream = Nothing
Set objFSO = Nothing
Response.ContentType = "application/x-unknown" ' arbitrary
fn = "ex"&request("exid")&"_score.txt"
FPath = "ex_score\" & fn
Response.AddHeader "Content-Disposition","attachment; filename=" & fn
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(FPath)
Response.BinaryWrite adoStream.Read()
adoStream.Close
Set adoStream = Nothing
Response.End
%>