 |
|
คำสั่ง readfile ของ ASP คำสั่ง readfile ของ ASP มี syntax ยังไงครับ คือว่า ผมจะมีลิ้งในการดาวน์โหลดไฟล์ .txt |
|
 |
|
|
 |
 |
|
Code (ASP)
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP TextStream Object</title>
</head>
<body>
<%
Dim objFSO, objStream
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objStream = objFSO.OpenTextFile(Server.MapPath("MyFiles/thaicreate.txt"))
Do Until objStream.AtEndOfStream
Response.Write objStream.ReadLine & "<br>"
Loop
objStream.Close
Set objStream = Nothing
Set objFSO = Nothing
%>
</body>
</html>
ASP Read Text File
|
 |
 |
 |
 |
Date :
2010-07-18 08:05:41 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอ้...ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2010-07-18 12:56:35 |
By :
blacklion |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่ว่านี่มันเป็นการอ่านไฟล์นี่ครับ คือผมอยากรู้ว่าการทำลิ้งค์ download ไฟล์ .txt อ่ะครับมันทำยังไง
ถ้าเป็น <a href="doc.txt">download</a> มันจะเป็นการเปิดไฟล์น่ะครับ
|
 |
 |
 |
 |
Date :
2010-07-18 12:59:47 |
By :
blacklion |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เว็บฝรั่งมา มืดตึ๊บ แต่ก็ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2010-07-19 00:26:26 |
By :
blacklion |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งะ มันมีตัวอย่างอยู่ด้านบน แค่ลิงค์ไปที่ไฟล์ๆ นั้น เค้าเรียก force download ครับผม
ถ้าเป็นการโหลดจากฐานข้อมูลที่เก็บชื่อ ก็สามารถ ปรับใช้ได้ โดยส่งไอดีหรือชื่อไฟล์ไปแล้ว ก็ไปจัดการมันในไฟล์นั้น อย่าให้มี output ออกมาละกัน
พอดีผมก็ไม่เคยเขียน force download ด้วย asp เหมือนกัน แต่หลักการเหมือน php นั่นแหละ แค่กำหนด header ให้มัน
ลองดูครับ ถ้ายังไม่ได้ ลองเอาโค๊ดมาแปะ เดี๋ยวช่วยดูอีกแรง
|
 |
 |
 |
 |
Date :
2010-07-19 00:35:08 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหอๆ ขอบคุณพี่ PlaKriM ไว้ล่วงหน้าครับ ผมแปะโค้ดให้นะครับ
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)
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
%>
|
 |
 |
 |
 |
Date :
2010-07-19 01:53:09 |
By :
blacklion |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|