1
我想强制用户下载YouTube视频。 例如this url。我下载视频,我可以播放原始视频,但即使是视频的长度/大小也是一样的,我不能在force_downloaded时播放它。强制下载mp4文件
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);
也许用户没有使用Apache! –
因此序言“如果您可以使用htaccess ...” – Eric
+1这比通过PHP解释器运行巨大的视频文件要好得多。 –