gpt4 book ai didi

php - 强制下载mp4文件

转载 作者:行者123 更新时间:2023-12-04 22:15:08 25 4
gpt4 key购买 nike

我想强制用户下载 youtube 视频。例如this网址。我下载了视频,我可以播放原始视频,但即使视频的长度/大小相同,我也无法在强制下载时播放。

function force_download($file,$video_url)
{

$video_data = file_get_contents($video_url);
file_put_contents($file, $video_data);

if(isset($file) && file_exists($file))
{
header('Content-length: ' . filesize($file));
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename= "' . $file . '"');

readfile($file);
}
}

force_download('youtube.mp4',$video_url);

最佳答案

如果你可以使用 htaccess...

<FilesMatch "\.(mp4|MP4)">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>

我也用它来强制下载 PDF。效果很好!

这是另一个关于使用 PHP 强制下载的堆栈问题...与我上面写的 htaccess 本质上是一样的。将内容配置设置为附件是关键。

How to force file download with PHP

编辑:嗯……但你已经做了类似的事情,但没有用……我想看看你是否能让 htaccess 与你正在尝试做的事情一起工作。

关于php - 强制下载mp4文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14366424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com