Reputation: 5695
I'm trying to download multiple files using header()
in a while
loop, but only one file gets downloaded. Why?
while ($row = mysql_fetch_array($sql)) {
header('Content-Type: text/x-vcard');
header('Content-Disposition: attachment; filename=' . $row['name'] . '.vcf');
}
Upvotes: 1
Views: 4330
Reputation: 18005
You can only transfer one file from server side at a time. Typical workarounds are:
Upvotes: 4
Reputation: 39724
headers ca be set only once before outputting any data.
As you loop you set some headers after that you must output something. In the next loop you will not set any headers.
Please read php.net
Upvotes: 1
Reputation: 91963
This is not possible. The HTTP protocol does not have support for downloading multiple files. The most common workaround is to put the files in a zip archive for the client to download.
Upvotes: 1