How to download multiple files together from a database in PHP
I know how to download a single file from a databas开发者_运维问答e in PHP. How can I download multiple files together from a database?
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?
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.
- Start output buffering.
- Set MIME type of the file to be downloaded.
- Prepare the file contents in buffer.
- Get the buffer contents and push it for download.
- 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.
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.
精彩评论