我有这个数组。如何在PHP中从URL下载多个文件?
$urls = array(
'0'=>'http://www.domain.com/media1.mp3'
'1'=>'http://www.domain.com/media2.mp3'
'2'=>'http://www.domain.com/media3.mp3'
)
我想在PHP的帮助下同时下载这些文件。
我该怎么做?有什么建议么?
我曾尝试将标题放入for循环,但它所做的是将所有文件的内容组合在一个大的mp3文件中。
这是我的尝试:
foreach($urls as $url)
{
ob_start();
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=".basename($url));
header("Content-Type: audio/mpeg");
header("Content-Transfer-Encoding: binary");
print file_get_contents($url);
ob_clean();
ob_flush();
flush();
sleep(1);
}
感谢 维沙尔
我也试过cURL!它不起作用。我也试过这个例子。 http://www.askapache.com/php/curl-multi-downloads.html#menu0-el1 但没有快乐! – Vishal 2010-08-17 16:43:14