tags:

views:

311

answers:

6

hi,

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.

thank you

+5  A: 

I think it's not possible since each HTTP request has only one URI.

metrobalderas
+1, for more info: http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
codaddict
Correct. HTTP requests have a specific start and end. You could probably abuse the protocol by writing a special client and serving the files as one file (much like a `tar` file or just a MIME `multipart`), but then we wouldn't be talking about a pure HTTP solution that works across all browsers anymore.
Alan
+4  A: 

That is practically not usable due to poor browser support. You can pack them into a tar or zip file at server side and serve the archive file though.

Ekin Koc
It *is* practically possible (Firefox proves it). But it is practically not useful since it’s only Firefox that supports it.
Gumbo
More clarification then :)BTW, since browser developers are leaning against more public stuff like html5 elements and CSS3, I doubt that we will see a widespread adoption of this anytime soon. Good to see that FF implemented it though.
Ekin Koc
+1  A: 

You can zip the file with PHP, serverside, and request the file or return it from within your script by setting the appropriate headers, see http://de3.php.net/manual/de/class.ziparchive.php

Or you create a special client that can parse your then self-specified message format (a flash app, a plugin) - but if your client is simply your browser you'll get one response with a fixed content-length from the server.

initall
+5  A: 

It is possible to send a multipart response in HTTP:

In general, HTTP treats a multipart message-body no differently than any other media type: strictly as payload. […] an HTTP user agent SHOULD follow the same or similar behavior as a MIME user agent would upon receipt of a multipart type.

[…] If an application receives an unrecognized multipart subtype, the application MUST treat it as being equivalent to "multipart/mixed".

But since Firefox is the only browser that I know about to support such multipart responses (apart from multipart/byterange), you should use some archive file format for this purpose.

Gumbo
A: 

Dunno about one HTTP request, but if you want them all at once you can loop through them while changing the header('Location:') for each of them while redirecting to the immediate download script. Though, that would be redundant, and ugly; I think the best way would be to zip them all, there are instructions on how to do so in the PHP Documentation.

henasraf
A: 

May be you can use JS to open multiple popups each loading a download URL. I hope its the only way..

Sathesh