You can make a zip of those files and force the user to download the zip.
Below is the function to perform the same.
PHP Code:
//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)
{
$zip->addFile($file_path.$files,$files);
}
$zip->close();
//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");
readfile("$archive_file_name");
exit;
}
PHP Code:
$file_names=array('test.php','test1.txt');
$archive_file_name='zipped.zip';
$file_path=dirname(__FILE__).'/';
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
Ι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.