0
我想用php下载一个视频/音频文件格式的远程URL。我曾尝试过以下 代码,其工作正常。但下载需要时间。如何以最快的方式下载。而且我还想获得下载的文件大小和文件的持续时间。请帮助我如何做到这一点。如何使用PHP从任何远程URL下载视频或音频文件?
我的代码在这里:
<?php
$remote_url = ; // Any remote url with direct file path
$content = get_headers($remote_url,1);
$content = array_change_key_case($content, CASE_LOWER);
if ($content['content-disposition']) {
$tmp_name = explode('=', $content['content-disposition']);
if ($tmp_name[1])
$realfilename = trim($tmp_name[1],'";\'');
} else
{
$stripped_url = preg_replace('/\\?.*/', '', $remote_url);
$realfilename = basename($stripped_url);
}
$remote_file_contents = file_get_contents($remote_url);
$local_file_path = $realfilename.'';
$song_copied = file_put_contents($local_file_path, $remote_file_contents);
?>
感谢&问候。