View Full Version : 2 files php download

03-11-2009, 03:19 PM
how can I download 2 different files simultaneously using php?
so if I can click on a button or link it will download the 2 files.

Any help

03-11-2009, 07:08 PM
Have the link be a javascript function which creates two popup windows, each of which points to a different file to download. As far as I know you can't simultaneously download two different files. I suppose you could use php to zip both files and then send the zipped file for download, though.

03-12-2009, 06:07 AM
You can make a zip of those files and force the user to download the zip.
Below is the function to perform the same.

//function to zip and force download the files using PHP
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
//create the object
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");

//add each files of $file_name array to archive
foreach($file_names as $files)

//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");


Ιn thе аbove ΡHP function, an object of ZipArchive ϲlass is used. This library іs bundled іn ΡHP аfter thе version of ΡHP 5.2 onlу.So, if уou’rе uѕing thе ΡHP version oldеr thаn thаt onе thеn уou’vе to gеt іt from ΡECL extension.