7 months ago

Exporting multiple files as .zip/rar file using phpoffice/phpword package

Posted 7 months ago by konrms

Hi guys,

I have managed to export multiple .doc files with phpoffice/phpword package, using a for loop and naming them according to id attribute (each file is named after by the according id number, eg. 15_en.doc, 16_en.doc etc):

//Controller excerpt 

foreach($regs as $i) //


$phpWord = new \PhpOffice\PhpWord\PhpWord();




//saving results:
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
		catch (Exception $e) 

					return response()->download(storage_path(''.$i->id.'_en.docx'));

The files are created and found inside the laravel\storage path.

  1. How can I automatically zip them as a single file?
  2. When the project runs on server, how can users download them on their own pc's over the network?

Thank you a lot!

Please sign in or create an account to participate in this conversation.