⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 download.asp

📁 教学平台
💻 ASP
字号:
<!-- #Include Virtual="/Inc/Conn.asp" -->
<%
  Response.Buffer = true
  Response.expires= 0
	Response.cachecontrol = false
  Response.Clear

  dim url
  Dim fso,fl,flsize, path
  Dim objStream,ContentType,flName,isre,url1
  dim rs, sql, id, fileName, fileExt
  '*********************************************调用时传入的资料的ID
  id=trim(request.querystring("id"))
  fileName = trim(request.querystring("title"))
  '******************************************************************
  If id="" Or Not isnumeric(id) Then
  	Response.ContentType = "text/html"
  	Response.charset = "gb2312"
  	Response.write "未指定资料ID"
  	Response.end
  End If

  If fileName="" Then
  	fileName = "未命名"
  End If


	'*********************************************根据ID取资料路径
	sql = "select path from StudyMaterial where id=" & id
	Set rs = Server.CreateObject("Adodb.recordset")
	rs.open sql,conn,1,1

	If rs.eof or rs.bof then
  	Response.ContentType = "text/html"
  	Response.charset = "gb2312"
  	Response.write "<script language='javascript'>alert('找不到指定资料');</script>"
  	Response.end
	Else
		path = rs("path")
		path = Server.mappath(path)

		Set fso=Server.CreateObject("Scripting.FileSystemObject")
	  Set fl=fso.getfile(path)
		flsize=fl.size
		flName=fl.name
		Set fl=Nothing
		Set fso=Nothing

	  Set objStream = Server.CreateObject("ADODB.Stream")
  	objStream.Open
  	objStream.Type = 1
  	objStream.LoadFromFile path

		fileExt = lcase(Right(flName, 4))
		fileName = fileName & fileext

	  Select Case fileExt
		  Case ".asf"
		  	ContentType = "video/x-ms-asf"
		  Case ".avi"
		  	ContentType = "video/avi"
		  Case ".doc"
		  	ContentType = "application/msword"
		  Case ".zip"
		  	ContentType = "application/zip"
		  Case ".xls"
		  	ContentType = "application/vnd.ms-excel"
		  Case ".gif"
		  	ContentType = "image/gif"
		  Case ".jpg", "jpeg"
		  	ContentType = "image/jpeg"
		  Case ".wav"
		  	ContentType = "audio/wav"
		  Case ".mp3"
		  	ContentType = "audio/mpeg3"
		  Case ".mpg", "mpeg"
		  	ContentType = "video/mpeg"
		  Case ".rtf"
		  	ContentType = "application/rtf"
		  Case ".htm", "html"
		  	ContentType = "text/html"
		  Case ".txt"
		  	ContentType = "text/plain"
		  Case Else
		  	ContentType = "application/octet-stream"
	  End Select

	  Response.AddHeader "Content-Disposition", "attachment; filename=" & fileName
  	Response.AddHeader "Content-Length", flsize
	  Response.Charset = "Gb2312"
  	Response.ContentType = ContentType
	  Response.BinaryWrite objStream.Read
  	Response.Flush
  	response.Clear()
  	objStream.Close
  	Set   objStream = Nothing
  End If
	set rs = nothing
	conn.close
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -