title: How to download multiple files from URL in PHP?
body: <p>I have this array.</p>
  
  <pre><code>$urls = array(
  '0'=&gt;'http://www.domain.com/media1.mp3'
  '1'=&gt;'http://www.domain.com/media2.mp3'
  '2'=&gt;'http://www.domain.com/media3.mp3'
  )
  </code></pre>
  
  <p>I wan to download these files simultaneously with the help of PHP.</p>
  
  <p>How do I do that? Any suggestions?</p>
  
  <p>I have tried putting headers in for loop but what it does is it combines the content of all files in one big mp3 file.</p>
  
  <p>This is what I tried:</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>Thanks
  Vishal</p>