Maison  >  Article  >  développement back-end  >  javascript - 怎么实现用户打开视频地址的时候不播放而是下载

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

WBOY
WBOYoriginal
2016-08-04 09:19:202390parcourir

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

回复内容:

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

用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,可以让浏览器默认下载文件连接,并且指定下载文件名。不过存在兼容问题,你可以试试
链接描述

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn