web app 怎么实现文件下载

w落七 2015-08-21 04:05:32
1.pc端web直接链接到想下载的文件,如果浏览器不支持打开,则会自动出现下载。但是手机浏览器不会自动下载,应该怎么做。
2.手机浏览器调用video标签,但是视频格式不支持的情况下,怎么打开视频。比如将iphone拍摄的视频(后缀为MOV)传到某个服务器,然后video标签链接到这个视频,该视频格式是无法打开的,修改后缀名为mp4或者ogg的话,谷歌浏览器可以打开,手机浏览器依然不行。
...全文
720 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanjie0929 2015-09-20
  • 打赏
  • 举报
回复
引用 4 楼 w落七的回复:
传到服务器,用手机上,这功能我做过
w落七 2015-08-28
  • 打赏
  • 举报
回复
w落七 2015-08-28
  • 打赏
  • 举报
回复
按照网上找到的资料,新建了一个dl.asp的文件,源码如下:

<%
Response.Buffer = true
Response.Clear	

'获取要下载的文件在服务器上的绝对位置
dlfile=trim(request("dlfile"))
  If dlfile<>"" Then
  fileurl=server.MapPath(dlfile)
  Else
  Response.end
  End If

'创建Myfso,使用FSO组件
  Set Myfso=Server.CreateObject("Scripting.FileSystemObject")
  Set f=Myfso.getfile(fileurl) '定义FSO对象f
    fsize=f.size '文件大小
    fName=f.name '文件名字
  Set f=Nothing  '释放f
  Set Myfso=Nothing '释放MyFso

'使用Adodb.Stream组件
Set MyStream = Server.CreateObject("ADODB.Stream")
MyStream.Open
MyStream.Type = 1
MyStream.LoadFromFile fileurl

'读取文件类型,让系统识别,以存为不同类型的文件。
Select Case lcase(Right(fName, 4))
  Case ".asf"
ContentType = "video/x-ms-asf"
  Case ".avi"
ContentType = "video/avi"
  Case ".doc","docx"
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 ".asp"
ContentType = "text/html"
  Case ".txt"
ContentType = "text/plain"
  Case Else
ContentType = "application/octet-stream"
  End Select

'下载
Response.AddHeader "Content-Disposition", "attachment; filename=" & fName
Response.AddHeader "Content-Length", fsize
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite MyStream.Read
Response.Flush

'释放MyStream
MyStream.Close
Set MyStream = Nothing
%>
在下载链接这样调用:

 <a class="a-share" href=“dl.asp?dlfile=share/1.txt">下载</a>
但是点击链接并没有下载,而是显示出一部分源码
w落七 2015-08-28
  • 打赏
  • 举报
回复
不能下载已经确定是浏览器问题,苹果自带浏览器会限制下载,并且苹果没有文件系统,下载了也找不到,安卓是可以下载的。视频文件仍旧不行,下载不了也无法播放。
yangtututu 2015-08-22
  • 打赏
  • 举报
回复
1. 一般都会自动下载 ,如果不能自动下载 设置 web服务器的 文件头标签 2.参考浏览器支持播放格式 压缩视频

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧