1、直接访问资源文件:
window.location.href = 'http://127.0.0.1/Uploads/Video/xxx.mp4';
2、使用php file函数操作
<?php
$filePath = $_GET['path'];
<!--解决中文名称乱码文件下载不了的问题-->
$filePath=iconv("utf-8","gb2312",$filePath);
<!--字节流 .*( 二进制流,不知道下载文件类型)-->
header( "Content-Type: application/octet-stream");
<!--当用户想把请求所得的内容存为一个文件的时候提供一个默认的文件名-->
header( "Content-Disposition: attachment;filename=".$filePath);
<!--告知下载客户端这是一个可以恢复续传的下载,存放本次下载的开始字节位置、文件的字节大小;-->
header("Accept-Ranges: bytes");
header( "Content-Length: ".filesize($filePath));
<!--以只读和二进制打开文件-->
$fd = fopen($filePath, "rb");
if($fd){
<!--feof函数检测是否已到文件尾-->
while(!feof($fd)) {
<!--读取文件-->
echo fread($fd, filesize($filePath));
}
<!--关闭文件-->
fclose($fd);
}
?>