1

I try to create a code to download multi file at once on one click

I use this code to read the name of the file from my database and take many file name in one variable using a href to page name download

this is the code

$file_query=mysqli_query($conn,"select * from tbl_taskimage where db_taskid='$id'")or die(mysqli_error($conn));
        $src = array();
if(mysqli_num_rows($file_query)>0){
    while($r=mysqli_fetch_array($file_query)){
    $src[]=$r['db_image'];}
    echo"<a href='download.php?src=".implode('/',$src)."'><img src='../img/download.png'></a>";
}

To dowload this file I use this code in download page

$src=$_GET['src'];echo $src;
$ex=explode("/",$src);
for($i=0;$i<count($ex);$i++){
$file_url = '../uploads_images/'.$ex[$i];
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
readfile($file_url);
}

The problem is I can't download all the files. Only the first file will be downloaded. How can I solve this problem when I click the on a href all files will be downloaded?

Philipp
  • 2,787
  • 2
  • 25
  • 27
m7md
  • 231
  • 3
  • 11
  • 4
    zip files before download .... or use javascript eg. http://stackoverflow.com/questions/18451856/how-can-i-let-a-user-download-multiple-files-when-a-button-is-clicked – donald123 Jan 12 '17 at 11:22
  • You can't initiate many responses at the same time. Create a single file archive for the user to download, or provide them the links to they can download them on their own. – yivi Jan 12 '17 at 11:28
  • the above comments are correct. The only way to do this is to put them all into a zip and then send the zip file to the client. – ADyson Jan 12 '17 at 13:34

0 Answers0