如何使用PHP从外部URL下载音频/视频文件?

时间:2019-01-05 23:19:52

标签: php http-headers

我想使用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下载所有内容。

0 个答案:

没有答案