0

I have a problem. I want to download multiple images form urls to visitor device. I dont need to zip the files. Just download one by one

This is my code :

$files = array(
    'https://example.com/image.jpg',
    'https://example.com/image2.jpg',
    'https://example.com/image3.jpg'
);

foreach($files as $file)
{
    $filename = 'images.jpg';

function forceDownload($filename, $type = "image/jpeg") {
    header('Content-Type: '.$type.'; charset=utf-8');
    header('Content-Disposition: attachment; filename="'.$filename.'"');
}

forceDownload($filename, "image/jpeg");
echo file_get_contents($file);
}

Thanks

Enryco ID
  • 3
  • 3

1 Answers1

0

You cant, HTTP doesn't provide a mechanism for sending multiple files over one request.

the only sensible way you can do this is to zip the images up into one zip file and download that.

OR...

display the images on the page and have a download button for each one individually I suppose.

Also your code is wrong, you are setting the file name to images.jpg and declaring a function every time you loop through the foreach loop.

Clint
  • 973
  • 7
  • 18