Download Multiple files in one HTTP request

2019-01-12 04:13发布

how is it possible to download multiple files in one HTTP request? what i mean it's like when you have multiple attachments and you select what you want to download then press download so they will be automaticcaly downloaded and you don't have to click on each one manually.

i'm using PHP as a serverside srcipting.

7条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-12 05:11

I'm using multiple invisible iframes to trigger multiple downloads at once. There will be more than one HTTP request, but the effect will be what you described.

<iframe style="display: none;" src="file1.zip"></iframe>
<iframe style="display: none;" src="file2.zip"></iframe>
<iframe style="display: none;" src="file3.zip"></iframe>

Most browsers will ask the user if they want to allow multiple downloads (this is to prevent letting website spamming the file system). Also, you have to make sure the file will actually be downloaded, and not just displayed inside the invisible iframe (e.g. by using header('Content-disposition: attachment'); inside the PHP script serving the file).

In my solution I use JavaScript to change the src after each file is downloaded, so the files load sequentially and my server has to handle fewer requests at once. But that solution requires AJAX and is much more complicated.

查看更多
登录 后发表回答