<!--#include file="CONN.ASP"-->
<!--#include file="cls_huayuweb()^191563631.asp"-->
<%
dim id
id=request.QueryString("id")
if id="" or not isnumeric(id) then oa.msgshow("非法操作！")
set rs=oa.execute("select filepath from c_kejian where id="&id)
if rs.eof then oa.msgshow("该学习资料不存在或已被删除！请返回重新选择！")
if rs(0)<>"" and not isnull(rs(0)) then
oa.execute("update c_kejian set hits=hits+1 where id="&id)
downloadFile(webdir&rs(0))
else
oa.msgclose("该文件已经被删除！")
end if
rs.close



function downloadFile(strFile) '下载文件
  dim strfilename,s,fso,f,intFilelength
 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>" & strFilename & " 此文件未找到！<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"
 
 Dim DataPart, PartSize,BytesRead
 BytesRead = 0
 
 Do While BytesRead < intFilelength
 
  PartSize = 64 * 1024
  if PartSize + BytesRead > intFilelength Then PartSize = intFilelength - BytesRead
  DataPart = s.Read(PartSize)
  BytesRead = BytesRead + PartSize
  Response.BinaryWrite(DataPart)
  Response.Flush
 Loop
 
 
 s.Close
 Set s = Nothing
 
End Function 
%>
