當前位置:編程學習大全網 - 腳本源碼 - ASP寫的文件代碼

ASP寫的文件代碼

分類: 電腦/網絡 >> 程序設計 >> 其他編程語言

問題描述:

在軟件信息上有壹個下載按鈕:

<a href="down?filename=<%=rs("filename")%>"><img src=images/download.gif border=0></a>

在down上計算下載次數,並下載文件:

<!--#include file="conn"-->

<%

set rs2 = server.CreateObject ("Adodb.recordset")

sql2="update downtimes set downtimes=(downtimes+1) where filename="&request("filename")

rs2.open sql2,conn,1,1

set rs2=nothing

set rs = server.CreateObject ("Adodb.recordset")

sql="select * from upfile where filename="&request("filename")

rs.open sql,conn,1,1

Response.Redirect rs("filepath")

%>

filepath壹般是“XXX.mp3”或“XXX.wma”、“XXX.doc”、“XXX”這樣的名稱,當點擊下載按鈕後,瀏覽器不顯示下載對話框,而是直接在瀏覽器中播放或是顯示這些文檔或圖片。請問有沒有什麽辦法,不讓瀏覽器調用本機播放器播放這些影音文件。當然,右鍵“目標另存為”可以下載,但是這樣就不能計算文件的下載次數了,有兩全其美的辦法麽?

解析:

Function downloadFile(strFile)

strFilename = server.MapPath(strFile)

Response.Buffer = True

Response.Clear

Set s = Server.CreateObject("ADODB.Stream")

s.Open

s.Type = 1

on error resume next

Set fso = Server.CreateObject("Scripting.FileSystemObject")

if not fso.FileExists(strFilename) then

Response.Write("<h1>Error:</h1> 文件不存在<p>")

Response.End

end if

Set f = fso.GetFile(strFilename)

intFilelength = f.size

s.LoadFromFile(strFilename)

if err then

Response.Write("<h1>Error: </h1>" & err.Description & "<p>")

Response.End

end if

Response.AddHeader "Content-Disposition", "attachment; filename=" &f.name

Response.AddHeader "Content-Length", intFilelength

Response.CharSet = "UTF-8"

Response.ContentType = "application/octet-stream"

Response.BinaryWrite s.Read

Response.Flush

s.Close

Set s = Nothing

End Function

看這個函數能幫到妳嗎

  • 上一篇:神秘的北緯30度未解之謎都有哪些
  • 下一篇:關於學雷鋒的黑板報內容
  • copyright 2024編程學習大全網