$zipFileName = 'tmp.zip';
$fileToInclude = 'files/file.txt';
$textToInclude = 'hello world';
$objZip = new ZipArchive();
$objZip->open($zipFileName, ZIPARCHIVE::CREATE);
$objZip->addFromString('readme.txt', $textToInclude);
$objZip->addFile($fileToInclude);
$objZip->close();
header('Content-disposition: attachment; filename='.$zipFileName);
header('Content-type: application/zip');
echo file_get_contents($zipFileName);