Antara
Antara

Reputation: 1

How to download multiple files together from a database in PHP

I know how to download a single file from a database in PHP. How can I download multiple files together from a database?

Upvotes: 0

Views: 476

Answers (3)

pMan
pMan

Reputation: 9158

I think you can't push multiple files at the same time in php. Since you have to set the MIME type of it, you can't set multiple headers at the same time.

You may be able to push files one after another, especially if you have to push files of different types. Output buffering can be used for it.

  1. Start output buffering.
  2. Set MIME type of the file to be downloaded.
  3. Prepare the file contents in buffer.
  4. Get the buffer contents and push it for download.
  5. Clean buffer.

repeat until all files are downloaded. Its better to store all files in server temporarily, then compress and push it as single file.

Upvotes: 1

user387302
user387302

Reputation: 405

I've never done anything like this, so this is more of a guess/suggestion/idea, but could you have a list somewhere with all the files you want to send and when each file is sent its marked/erased from the list; then you refresh the page and go down to the next file in the list ? Not sure if this would work not, just my 2 cents.

Upvotes: 0

Matt Williamson
Matt Williamson

Reputation: 40193

You can theoretically do multipart to push multiple files, but I think it will be exceedingly difficult. Perhaps you can zip the files up and then push the zip to the browser?

Upvotes: 3

Related Questions