怎么实现用户打开视频地址的时候不播放而是下载
怎么实现用户打开视频地址的时候不播放而是下载
用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>引用了鸟哥的代码:http://www.laruence.com/2012/...
a标签H5有个新属性download,可以让浏览器默认下载文件连接,并且指定下载文件名。不过存在兼容问题,你可以试试
链接描述
立即学习“Java免费学习笔记(深入)”;
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号