【发布时间】:2019-09-23 20:51:23
【问题描述】:
好的,我知道这听起来像是重复的,但事实并非如此。 有很多关于下载 mp4 文件而不是通过浏览器播放的问题和答案。
我的问题是我的 mp4 大小为 1GB,而我的服务器有 512 个内存和 1 个 CPU,所以这种方法对我不起作用。
这是我当前的代码:
<?php
ini_set('memory_limit', '-1');
$file = $_GET['target'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>
有没有办法让它在一个大文件上发生?
【问题讨论】:
-
在.htaccess 中使用
Header指令设置标题并直接链接文件怎么样? -
@MichalHynčica 我只是在学习人:D
-
我没有尝试过,所以我只在 cmets 中建议它。但我相信如果使用 php 的唯一原因是设置 headers,最好用mod_headers 设置它们并让 apache 处理发送文件而不是在 php 中打开它。
-
另外,mime 类型应该是
application/octet-stream而不是八位字节/流。