>  기사  >  백엔드 개발  >  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으로 문의하세요.