欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【ASP实现文件直接下载】,下面是详细的分享!
ASP实现文件直接下载
<%@ language=vbscript codepage=65001%>
<%
'Filename must be input
if Request("Filename")="" then
response.write "<h1>Error:</h1>Filename is empty!<p>"
else
call downloadFile(replace(replace(Request("Filename"),"\",""),"/",""))
Function downloadFile(strFile)
' make sure you are on the latest MDAC version for this to work
' get full path of specified file
strFilename = server.MapPath(strFile)
' clear the buffer
Response.Buffer = True
Response.Clear
' create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open
' Set as binary
s.Type = 1
' load in the file
on error resume next
' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>"&strFilename&" does not exists!<p>")
Response.End
end if
' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>Unknown Error!<p>")
Response.End
end if
' send the headers to the users Browse
Response.AddHeader "Content-Disposition","attachment; filename="&f.name
Response.AddHeader "Content-Length",intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush
' tidy up
s.Close
Set s = Nothing
End Function
end if
%>
以上所分享的是关于ASP实现文件直接下载,下面是编辑为你推荐的有价值的用户互动:
相关问题:ASP 如何实现文件下载
答:你把要下载的文件名传到下载页面,用request("fileNameField")获取文件名 下面这地方改一下 iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _ ";Data Source=" & server.mappath(request("fileNameField")) 点击... >>详细
相关问题:如何在asp.net中如何实现文件的下载功能。
答:protected void BtnDownload_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sql"].ToString()); conn.Open(); string strSql = "select top 1 timage from test"; SqlC... >>详细
相关问题:如何在asp.net中实现点击下载按钮进行文件下载?
答:在page_load事件里加: string filename = Path.GetFileName( filepath ); Response.Clear(); Response.ContentType = "application/octet-stream "; Response.AppendHeader( "Content-Disposition ", "attachment; Filename = " + System.Conve... >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
