tags:

views:

34

answers:

3

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

+2  A: 

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?

Matt Williamson
A: 

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.

+1  A: 

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.

pMan
What would browser say to that?
Col. Shrapnel
Browsers may not work (many types in single response), even though its possible at server side. I have not tried multiple downloads, but using buffers for other purpose works very well with multiple MIME types. So effectively, temporarily store all files at server and compress to push as single file.
pMan