views:

390

answers:

6

Hi,

i am in a need to download more than one file from the server (PHP) on a single click. it is possible to download one file but didnt work for multiple file at a time (suppose files are in diff. directories). i am using WAMP, please help me.

thanks and regards

tismon

+5  A: 

Not quite sure what you are asking, if you are asking for a way to get a server to serve multiple files to a user with one request, then you probably need to go with a zip file or some other archive format.

James Deville
+6  A: 

Simply zip the files on server and send the archive, like Gmail does with multiple attachments. Most modern operating systems should have no trouble uncompressing the package, some of them will do it on the fly (without user having to do anything). I don’t know PHP, but there seems to be a zip library, see the examples on PHP’s website.

zoul
Easy enough, the most *standard* method, and certainly much more user friendly than throwing potentially dozens of Save As dialogs in the user's face.
Wim
+1  A: 

You could send the user an email with links or even attachment if the file sizes are small.

Tim Santeford
+1  A: 

With PHP, it's not possible. You can only serve one file per request. However, you can invoke the browser to download multiple files by using a little JavaScript:

var files = ['fileone.zip', 'filetwo.zip'];
for (var i = 0; i < files.length; i++){
    window.open(files[i], 'Download file');
}

It's really pretty nasty though. I'd just go with a zip.


PS. If you want to download html files with this method, you need to send out the Content-Disposition header for each file, to ensure the document doesn't just get rendered in the popup window spawned by window.open:

header('Content-Disposition: attachment; filename="todownload.html"');
brianreavis
A: 

You could create an IFrame and in Javascript set the source of the IFrame to your various download files. If you run in to timing issues with the downloads you could try a download delay or use multiple IFrames (but that last one seems ugly).

Tuzo
A: 

I commented here with the solution I came up with:

http://peter.worksontheweb.net/post/Sequentially-download-multiple-files-(with-jQuery).aspx

Guy Schalnat