Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP multiple file download

I've seen this example on the documentation for PHP readfile

<?php
$file = 'monkey.gif';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>

How can you make it so It download multiple files say monkey.gif and girraffe.jpg

Preferably without ZIP files...

like image 395
Mark Lalor Avatar asked Dec 16 '22 21:12

Mark Lalor


1 Answers

You can't. It's not a PHP limitation, it's an HTTP/Web-Browser limitation. HTTP doesn't provide a mechanism for sending multiple files over one request.

You could, however, have some PHP script that generates multiple iframes, which would initiate one download each, and fake it that way.

like image 73
timdev Avatar answered Dec 29 '22 11:12

timdev