I have the following code to download some log files through code
$files = array( '../tmp/logs/debug.log',
'../tmp/logs/error.log');
foreach($files as $file) {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: text/html");
header("Content-Transfer-Encoding: binary");
// read the file from disk
readfile($file);
}
But only download the first element of the array. In this case debug.log , if i swap the elements then only error.log. Any help please ?
You can only download one file per HTTP request. Effectively once the first file is sent the browser will assume that's the end of the processing and stops talking to the server.
If you want to ensure that the user downloads multiple files, one solution might be to zip them all up on-the-fly at the server-side, and then send the zip file to the user to download instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With