I am trying to find a way to download files in a loop.
The first call to the function is executed (so the first file -file1.exe- is downloaded).

Every next call to the function (file2 and file3) however is not executed.
Anyone knows how to solve it ?

Code:
<?php

downloadfile('../downloads/file1.exe');
downloadfile('../downloads/file2.exe');
downloadfile('../downloads/file3.exe');

function downloadfile($file)
{
 // fix for IE catching or PHP bug issue
 header("Pragma: hack");
 header("Expires: 0"); // set expiration time
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 // browser must download file from server instead of cache

 // use the Content-Disposition header to supply a recommended filename and
 // force the browser to display the save dialog.
 header("Content-Disposition: attachment; filename=" . basename($file));   
 
 // force download dialog
 header("Content-Type: application/force-download");
 header("Content-Type: application/octet-stream");
 header("Content-Type: application/download");
 header("Content-Description: File Transfer");            
 
 /*
 The Content-transfer-encoding header should be binary, since the file will be read
 directly from the disk and the raw bytes passed to the downloading computer.
 The Content-length header is useful to set for downloads. The browser will be able to
 show a progress meter as a file downloads. The content-lenght can be determines by
 filesize function returns the size of a file.
 */
 header("Content-Transfer-Encoding: binary");
 header("Content-Length: " . filesize($file));

 flush(); // this doesn't really matter.

 $fp = fopen($file, "r");
 while (!feof($fp))
  {
   echo fread($fp, 65536);
   flush(); // this is essential for large downloads
  } 
 fclose($fp); 
}

?>