首页  >  文章  >  后端开发  >  javascript - 怎么实现用户打开视频地址的时候不播放而是下载

javascript - 怎么实现用户打开视频地址的时候不播放而是下载

WBOY
WBOY原创
2016-08-04 09:19:202385浏览

怎么实现用户打开视频地址的时候不播放而是下载

回复内容:

怎么实现用户打开视频地址的时候不播放而是下载

用PHP来代理下载

<code><?php $file = "/tmp/视频.mp4";
    $filename = basename($file);
    header("Content-type: application/octet-stream");
    //处理中文文件名
    $ua = $_SERVER["HTTP_USER_AGENT"];
    $encoded_filename = rawurlencode($filename);
    if (preg_match("/MSIE/", $ua)) {
     header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
    } else if (preg_match("/Firefox/", $ua)) {
     header("Content-Disposition: attachment; filename*=\"utf8''" . $filename . '"');
    } else {
     header('Content-Disposition: attachment; filename="' . $filename . '"');
    }
    header("Content-Length: ". filesize($file));
    readfile($file);</code></code>

引用了鸟哥的代码:http://www.laruence.com/2012/...

a标签H5有个新属性download,可以让浏览器默认下载文件连接,并且指定下载文件名。不过存在兼容问题,你可以试试
链接描述

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn