如何强制浏览器下载而不是播放巨大的mp4文件 [英] How to force browser to download HUGE mp4 file instead of playing it

查看:219
本文介绍了如何强制浏览器下载而不是播放巨大的mp4文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我知道这听起来像是重复的,但事实并非如此。
关于下载mp4文件而不是通过浏览器播放它有很多问题和答案。

Okay , I know it sounds like duplicate but it's not. there's a lot of questions and answers about downloading a mp4 file instead of playing it by browser.

我的问题是我的mp4大小为1GB,服务器为512 ram和1 CPU因此,这种方法对我不起作用。

my issue is my mp4 has 1GB size and my server has 512 ram and 1 CPU so , this methods are not working for me.

这是我当前的代码:

<?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;
?>

有什么方法可以使它在巨大的文件上发生?

Is there any way to make it happen on a huge file ?

推荐答案

您是否尝试过分块下载文件,例如:

Have you tried downloading the file in chunks, e.g.:



$chunk = 256 * 256; // you can play with this - I usually use 1024 * 1024;
$handle = fopen($file, 'rb');
while (!feof($handle))
{
    $data = fread($handle, $chunk);
    echo $data;
    ob_flush();
    flush();
}
fclose($handle);

这篇关于如何强制浏览器下载而不是播放巨大的mp4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆