我想使用PHP从远程URL下载视频/音频。
在下载之前,我知道我确实有填充标头信息。
我尝试使用不同的标头,这些标头是在互联网上找到的。但至少没有运气。
<?php
$FileName = 'test.mp4';
$Link = 'https://my-external-url/this-is-a-video-example';
$ContentType = get_headers($Link, 1)["Content-Type"];
header('Content-disposition: attachment; filename="' . $FileName . '"');
header('Content-type: ' . $ContentType . '');
readfile($Link);
?>
结果始终是,正在下载的文件中包含0 kilobytes
。
很遗憾,我无法共享该URL,因为该URL位于访问受限的环境中。
但是我的问题是:
我的意思是它可以是MP4
的远程URL或具有only audio
的远程URL。我希望使我的PHP像一个函数,该函数可以基于LINK(总是不同)使用correct header infromation
下载所有内容。