我有這個數組。如何在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