API to download multiple files in single get request

Hi,

I have created an API in the index file in the slim framework.
Something as below ':

$app->get('/getXML', function (Request $request, Response $response) {
    
    $file = PROJECT_ROOT . '/library/8.txt';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment;filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}

I wanted to create an API that can let me download multiple files in one request.
like hit getMultiFiles, and I am able to download 1.txt, 2.txt and 3.txt.
Could you help me out please?

Thanks,
Reema

HTTP does not support more than one file download at once.

There are two solutions:

  • Open x amount of windows to initiate the file downloads (this would be done with JavaScript)
  • preferred solution create a script to zip the files

It has never been a problem to send multiple files in one unique form.
There is no need to take the hard way :

https://www.slimframework.com/docs/v3/cookbook/uploading-files.html

@liva The question was about “downloading” not “uploading”.

sorry for that :sweat: